Skip to main content

Handy decorator to set retry policies for async callables with some handy features

Project description

aioretry

Handy decorator to set retry policies for async callables with some handy features

Usage examples

@retry(
    tries=5,
    allowed_exceptions=(RuntimeError,),
    intervals=(5, 7, 10),
    fail_cb=make_request_callback,
)
async def make_request(address, client):

    ... http request code goes here...

    if response.status_code >= 300:
        raise RuntimeError()

def make_request_callback(address, client)
    ...
  • 5 retries will be performed
  • with 5, 7, 10, 10 and 10 seconds interval between retries. I.e. if intervals tuple length more than tries number, the last tuple interval will be used for the rest of the tries.
  • make_request_callback() synchronous function will be called if all attempts are failed
  • The accepted exceptions tuple allows you to control when to retry.
  • You can optionally pass a custom logger: logging.Logger to the decorator within a logger= parameter. Otherwise retry_decorator logger will be created to log retries.

Other possible ways to use this decorator:

@retry(5, (MyCustomError,), (5, 7, 10), make_request_callback)

@retry(3, (MyCustomError,), (1,))

# this actually will either successfully return or fail on first exception occured
@retry(3)

Look into tests.py to see more on usage.

Install as package via pip

pip install git+https://github.com/remort/aioretry.git#egg=aioretry_decorator

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aioretry-decorator-1.0.1.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file aioretry-decorator-1.0.1.tar.gz.

File metadata

  • Download URL: aioretry-decorator-1.0.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.2 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.14 CPython/3.10.6

File hashes

Hashes for aioretry-decorator-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c29d666dbf791da9d9749c3f82896c7d1fd7482c455b9d961f76ed4bf874717a
MD5 6df14ea9a2cad92c12fcba8bb43c597b
BLAKE2b-256 6da95bb444b488720325b56b760f275549c199db3ef750003879a6b78c38f83d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page