Activate the ``pyramid_retry`` execution policy in your application.

    This will add the :func:`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')``.

def includeme(config):
    """
    Activate the ``pyramid_retry`` execution policy in your application.

    This will add the :func:`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')``.

    """
    settings = config.get_settings()

    config.add_view_predicate('last_retry_attempt', LastAttemptPredicate)
    config.add_view_predicate('retryable_error', RetryableErrorPredicate)

    def register():
        attempts = int(settings.get('retry.attempts') or 3)
        settings['retry.attempts'] = attempts

        activate_hook = settings.get('retry.activate_hook')
        activate_hook = config.maybe_dotted(activate_hook)

        policy = RetryableExecutionPolicy(
            attempts,
            activate_hook=activate_hook,
        )
        config.set_execution_policy(policy)

    # defer registration to allow time to modify settings
    config.action(None, register, order=PHASE1_CONFIG)