adapters: handle 204's on HttpAdapter
- adapters: add debug info on ping errors
This commit is contained in:
parent
37724f2d21
commit
6b82684d5a
1 changed files with 11 additions and 7 deletions
|
@ -70,12 +70,13 @@ class PingAdapter(Adapter):
|
|||
# we dont need to keep sending err_msg on alive scenarios
|
||||
return cls._construct(alive, latency)
|
||||
|
||||
# only log on errors
|
||||
worker.log.info(f'alive={alive} latency={latency}ms')
|
||||
|
||||
err = PING_ERROR_RGX.search(out)
|
||||
err_msg = err.group(2) if not alive and err else 'packet lost'
|
||||
|
||||
# only log on errors
|
||||
worker.log.info(f'alive={alive} latency={latency}ms '
|
||||
f'err={err_msg!r} out={out}')
|
||||
|
||||
return cls._construct(alive, latency, err_msg)
|
||||
|
||||
|
||||
|
@ -87,9 +88,11 @@ class HttpAdapter(Adapter):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def get_phrase(cls, status: int):
|
||||
with open('./status.json', 'r') as fd:
|
||||
statuses = json.load(fd)
|
||||
def get_phrase(cls, status: int) -> str:
|
||||
"""Get a string representing the error
|
||||
given by the http status code."""
|
||||
with open('./status.json', 'r') as status_file:
|
||||
statuses = json.load(status_file)
|
||||
|
||||
try:
|
||||
return statuses[str(status)]
|
||||
|
@ -105,7 +108,8 @@ class HttpAdapter(Adapter):
|
|||
resp = await session.get(f'{adp_args["url"]}')
|
||||
t_end = time.monotonic()
|
||||
|
||||
succ = resp.status == 200
|
||||
# handle both 200 and 204
|
||||
succ = resp.status in (200, 204)
|
||||
latency = round((t_end - t_start) * 1000)
|
||||
|
||||
# drop latency to 0 to signal a non-success
|
||||
|
|
Loading…
Reference in a new issue