{"id":25961878,"url":"https://github.com/nameko/nameko-amqp-retry","last_synced_at":"2025-03-04T19:50:06.098Z","repository":{"id":57444748,"uuid":"70499279","full_name":"nameko/nameko-amqp-retry","owner":"nameko","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-19T03:06:28.000Z","size":88,"stargazers_count":25,"open_issues_count":6,"forks_count":5,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-02-25T21:56:20.394Z","etag":null,"topics":["amqp","microservices","nameko","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nameko.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-10T15:03:05.000Z","updated_at":"2024-11-20T03:52:46.000Z","dependencies_parsed_at":"2022-09-26T17:30:35.407Z","dependency_job_id":null,"html_url":"https://github.com/nameko/nameko-amqp-retry","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nameko%2Fnameko-amqp-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nameko%2Fnameko-amqp-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nameko%2Fnameko-amqp-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nameko%2Fnameko-amqp-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nameko","download_url":"https://codeload.github.com/nameko/nameko-amqp-retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241444155,"owners_count":19963758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amqp","microservices","nameko","python"],"created_at":"2025-03-04T19:50:04.037Z","updated_at":"2025-03-04T19:50:06.086Z","avatar_url":"https://github.com/nameko.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"nameko-amqp-retry\n=================\n\nExtension for `nameko \u003chttp://nameko.readthedocs.org\u003e`_ that allows the built-in AMQP entrypoints to schedule a later retry via redelivery of a message.\n\nRabbitMQ 3.5.4 or later is required.\n\n\nInstallation\n------------\n\nInstall the library from PyPI::\n\n    pip install nameko-amqp-retry\n\n\nUsage\n-----\n\nThis library subclasses nameko's built-in entrypoints. Use these subclasses in your service definition, and then raise :class:`nameko_amqp_retry.Backoff` inside an entrypoint you wish to retry later:\n\n.. code-block:: python\n\n    from nameko_amqp_retry import Backoff\n    from nameko_amqp_retry.rpc import rpc\n\n    class Service:\n        name = \"service\"\n\n        @rpc\n        def calculate(self):\n            \"\"\" Calculate something, or schedule a retry if not ready yet.\n            \"\"\"\n            if not_ready_yet:\n                raise Backoff()\n\n            return 42\n\nThe caller will see the final result, or a :class:`Backoff.Expired` exception if more than the allowed number of retries were made:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e n.rpc.service.calculate()\n    ... # blocks for some time\n    \u003e\u003e\u003e 42\n\n.. code-block:: python\n\n    \u003e\u003e\u003e n.rpc.service.calculate()\n    Traceback (most recent call last):\n      ...\n    nameko.exceptions.RemoteError: Expired Backoff aborted after ...\n\nThe retry schedule is controlled by attributes on the `Backoff` class. You should override them in a subclass to control the behaviour. For example:\n\nFixed schedule:\n\n.. code-block:: python\n\n    class RegularBackoff(Backoff):\n        \"\"\" Retries every 1000ms until limit\n        \"\"\"\n        schedule = (1000,)  # ms\n\nNo limit:\n\n.. code-block:: python\n\n    class InfiniteBackoff(Backoff):\n        \"\"\" Retries forever\n        \"\"\"\n        limit = 0\n\n\nCustom schedule:\n\n.. code-block:: python\n\n    class ImpatientBackoff(Backoff):\n        \"\"\" Retries after 100, then 200, then 500 milliseconds\n        \"\"\"\n        schedule = (100, 200, 500)  # ms\n\n\nDynamic schedule:\n\n.. code-block:: python\n\n    class DynamicBackoff(Backoff):\n        \"\"\" Calculates schedule dynamically\n        \"\"\"\n        @classmethod\n        def get_next_schedule_item(cls, index):\n            ...\n\nAlternatively, an entrypoint can be decorated with the `entrypoint_retry` decorator, to automatically retry the method if it raises certain exceptions:\n\n.. code-block:: python\n\n    from nameko_amqp_retry import entrypoint_retry\n    from nameko_amqp_retry.rpc import rpc\n\n    class Service:\n        name = \"service\"\n\n        @rpc\n        @entrypoint_retry(retry_for=ValueError)\n        def calculate(self):\n            \"\"\" Calculate something, or schedule a retry if not ready yet.\n            \"\"\"\n            if not_ready_yet:\n                raise ValueError()\n\n            return 42\n\n        @rpc\n        @entrypoint_retry(\n            retry_for=(TypeError, ValueError),\n            limit=5,\n            schedule=(500, 600, 700, 800, 900),\n        )\n        def do_something(self):\n            \"\"\" Calculate something else, or schedule a retry if not ready yet.\n            \"\"\"\n            if type_not_ready_yet:\n                raise TypeError()\n\n            if value_not_ready_yet:\n                raise ValueError()\n\n            return 24\n\n\nSee docs/examples for more.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnameko%2Fnameko-amqp-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnameko%2Fnameko-amqp-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnameko%2Fnameko-amqp-retry/lists"}