pyramid_retry API

pyramid_retry.includeme(config)[source]

Activate the pyramid_retry execution policy in your application.

This will add the pyramid_retry.RetryableErrorPolicy() with attempts pulled from the retry.attempts setting.

The last_retry_attempt and retryable_error view predicates are registered.

This should be included in your Pyramid application via config.include('pyramid_retry').

pyramid_retry.RetryableExecutionPolicy(attempts=3, activate_hook=None)[source]

Create a execution policy that catches any retryable error and sends it through the pipeline again up to a maximum of attempts attempts.

If activate_hook is set it will be consulted prior to each request to determine if retries should be enabled. It should return a number > 0 of attempts to be used or None which will indicate to use the default number of attempts.

pyramid_retry.mark_error_retryable(error)[source]

Mark an exception instance or type as retryable. If this exception is caught by pyramid_retry then it may retry the request.

pyramid_retry.is_error_retryable(request, exc)[source]

Return True if the exception is recognized as retryable error.

This will return False if the request is on its last attempt. This will return False if pyramid_retry is inactive for the request.

pyramid_retry.is_last_attempt(request)[source]

Return True if the request is on its last attempt, meaning that pyramid_retry will not be issuing any new attempts, regardless of what happens when executing this request.

This will return True if pyramid_retry is inactive for the request.

class pyramid_retry.LastAttemptPredicate(val, config)[source]

A view predicate registered as last_retry_attempt. Can be used to determine if an exception view should execute based on whether it's the last retry attempt before aborting the request.

class pyramid_retry.RetryableErrorPredicate(val, config)[source]

A view predicate registered as retryable_error. Can be used to determine if an exception view should execute based on whether the exception is a retryable error.

exception pyramid_retry.RetryableException[source]

A retryable exception should be raised when an error occurs.

interface pyramid_retry.IRetryableError[source]

A marker interface for retryable errors.

An interface can be applied to any Exception class or object to indicate that it should be treated as a retryable error.

interface pyramid_retry.IBeforeRetry[source]

An event emitted immediately prior to throwing away the request and creating a new one.

This event may be useful when state is stored on the request.environ that needs to be updated before a new request is created.

environ

The environ object that is reused between requests.

request

The request object that is being discarded.

exception

The exception that request processing raised.

response

The response object that is being discarded. This may be None if no response was generated, which happens when request processing raises an exception that isn't caught by any exception view.