Coverage for gwcelery/tasks/legacy_gracedb.py: 55%
20 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
1"""Communication with GraceDB using the legacy GraceDB client."""
2import functools
3from http.client import HTTPException
4from socket import gaierror
6from ligo.gracedb import rest
8from .. import app
9from ..util import PromiseProxy
11client = PromiseProxy(rest.GraceDb,
12 ('https://' + app.conf.gracedb_host + '/api/',),
13 {'fail_if_noauth': True, 'reload_certificate': True})
16class RetryableHTTPError(rest.HTTPError):
17 """Exception class for server-side HTTP errors that we should retry."""
20def catch_retryable_http_errors(f):
21 """Decorator to capture server-side errors that we should retry.
23 We retry HTTP status 502 (Bad Gateway), 503 (Service Unavailable), and
24 504 (Gateway Timeout).
25 """
26 @functools.wraps(f)
27 def wrapper(*args, **kwargs):
28 try:
29 return f(*args, **kwargs)
30 except rest.HTTPError as e:
31 if e.status in {408, 409, 429, 502, 503, 504}:
32 raise RetryableHTTPError(e.status, e.reason, e.message)
33 else:
34 raise
36 return wrapper
39def task(*args, **kwargs):
40 return app.task(*args, **kwargs,
41 autoretry_for=(gaierror, RetryableHTTPError,
42 TimeoutError, HTTPException),
43 default_retry_delay=20.0, retry_backoff=True,
44 retry_kwargs=dict(max_retries=10))