Skip to content

Commit

Permalink
fix: retrying with greater backoff to fetch routers list
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed May 3, 2024
1 parent 7a307e9 commit e128e00
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions imageroot/bin/write-hosts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ Allows to notify modules of the change.
import json
import os
import re
import requests

from urllib3.util import Retry
from requests import Session
from requests.adapters import HTTPAdapter
from requests.exceptions import RequestException

import agent

# Fetch router list from traefik
api_path = os.environ["API_PATH"]
try:
response = requests.get(f'http://127.0.0.1/{api_path}/api/http/routers').json()
except requests.exceptions.RequestException as e:
raise Exception(f'Error reaching traefik daemon: {e}')
session = Session()
retries = Retry(
backoff_factor=0.5,
)
session.mount('http://', HTTPAdapter(max_retries=retries))
response = session.get(f'http://127.0.0.1/{api_path}/api/http/routers').json()
session.close()

# Connect to redis using module credentials
agent_id = os.getenv("AGENT_ID")
Expand Down

0 comments on commit e128e00

Please sign in to comment.