Merge pull request #53 from SUNET/patlu-fleetlock-error-handling
sunet-fleetlock: handle connection errors
This commit is contained in:
commit
5d88e66379
|
@ -24,20 +24,21 @@
|
|||
# When modifying this code please make sure it is passed through the following
|
||||
# tools:
|
||||
# ===
|
||||
# isort
|
||||
# black
|
||||
# pylint
|
||||
# mypy --strict
|
||||
# ===
|
||||
|
||||
import platform
|
||||
import sys
|
||||
import signal
|
||||
import time
|
||||
import argparse
|
||||
import configparser
|
||||
import os.path
|
||||
from typing import Optional, Union
|
||||
import platform
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
from types import FrameType
|
||||
from typing import Optional, Union
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -80,19 +81,26 @@ def do_fleetlock_request(
|
|||
request_id_key = "request-id"
|
||||
request_id = None
|
||||
|
||||
retry_sleep_delay = 1
|
||||
|
||||
# Loop forever: we depend on the SIGALRM timout to raise an error if it
|
||||
# takes too long
|
||||
while True:
|
||||
if args.verbose:
|
||||
print(f"{operation} POST at url {url}")
|
||||
|
||||
try:
|
||||
resp = requests.post(
|
||||
url,
|
||||
headers=fleetlock_headers,
|
||||
json=fleetlock_data,
|
||||
timeout=args.timeout,
|
||||
timeout=args.request_timeout,
|
||||
auth=("", config[args.lock_group]["password"]),
|
||||
)
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print(f"POST request failed: {e}")
|
||||
time.sleep(retry_sleep_delay)
|
||||
continue
|
||||
|
||||
if request_id_key in resp.headers:
|
||||
request_id = resp.headers[request_id_key]
|
||||
|
@ -126,7 +134,7 @@ def do_fleetlock_request(
|
|||
+ f"({request_id_key}: {request_id})"
|
||||
)
|
||||
|
||||
time.sleep(1)
|
||||
time.sleep(retry_sleep_delay)
|
||||
|
||||
|
||||
def read_config(args: argparse.Namespace) -> Union[configparser.ConfigParser, None]:
|
||||
|
|
Loading…
Reference in a new issue