Skip to main content

Retries library

Project description

Library to make your services reliable

Retry on specific exception

import yretry

@yretry.decorators.retry(attempts_number=3,
                         retry_on=(MyException,))
def reliable_function():
    raise MyException()

Specific function to make decision about retries

import yretry

def is_my_mistake(error):
    return isinstance(error, MyMistake)

@yretry.decorators.retry(attempts_number=3,
                         retry_on=is_my_mistake)
def reliable_function():
    raise MyMistake()

Retry on network errors

You can use following code to add retries for your custom network function:

import requests
import yretry

@yretry.network.retry()
def reliable_function():
   response = requests.get('http://localhost:5002')
   response.raise_for_status()
   return response

print reliable_function()

Logging

Global logger

You can pass specific logger to decorator:

import logging
import logging.config

LOGGING = {
    'version': 1,
    'formatters': {
        'precise': {
            'datefmt': '%Y-%m-%d,%H:%M:%S',
            'format': '%(levelname)-7s %(asctime)15s '
                      '%(name)s:%(lineno)d %(message)s'
        }
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'precise',
            'stream': 'ext://sys.stderr'
        },
    },
    'root': {
        'level': 'INFO',
        'handlers': ['console']
    }
}

logging.config.dictConfig(LOGGING)

LOGGER = logging.getLogger(__name__)

@yretry.network.retry(logger=LOGGER)
def reliable_function():
   response = requests.get('http://localhost:5002')
   response.raise_for_status()
   return response

Object-specific logger

You can use object-specific logger, just add ‘get_logger’ method:

class MyClass(object):
   def __init__(self):
       self._logger = logging.getLogger(__name__)

   def get_logger(self):
       return self._logger

   @yretry.network.retry()
   def reliable_method(self):
       pass

obj = MyClass()
obj.reliable_method()
# obj._logger will be used to write warnings about retries

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

yretry-1.0.2.tar.gz (92.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yretry-1.0.2-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file yretry-1.0.2.tar.gz.

File metadata

  • Download URL: yretry-1.0.2.tar.gz
  • Upload date:
  • Size: 92.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yretry-1.0.2.tar.gz
Algorithm Hash digest
SHA256 acf2b9234b7b9e474210171c0771cfcd552368a721f86046d877de7be5dc8d82
MD5 c42b992d63abf58dcef405f0b82945ce
BLAKE2b-256 e919b90907af922e18d51c1c99a8317bed18fe7f4b0dedf43967d66a09e62afc

See more details on using hashes here.

Provenance

The following attestation bundles were made for yretry-1.0.2.tar.gz:

Publisher: publish-to-pypi.yml on infraguys/yretry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yretry-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: yretry-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yretry-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b55846aef40e2dca579c39fad1ee0a89f8f054badade67dd4e2d56cd8b11e36d
MD5 19a6a8ad692cdd1958ceee5fe970f584
BLAKE2b-256 e195d58b69bbad6592128b78dd8ccb89701540e050f6770762e273af89fe428c

See more details on using hashes here.

Provenance

The following attestation bundles were made for yretry-1.0.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on infraguys/yretry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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