Nameko extension allowing AMQP entrypoints to retry later
Project description
nameko-amqp-retry
=================
Extension for `nameko <http://nameko.readthedocs.org>`_ that allows the built-in AMQP entrypoints to schedule a later retry via redelivery of a message.
RabbitMQ 3.5.4 or later is required.
Installation
------------
Install the library from PyPI::
pip install nameko-amqp-retry
Usage
-----
This 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:
.. code-block:: python
from nameko_amqp_retry import Backoff
from nameko_amqp_retry.rpc import rpc
class Service:
name = "service"
@rpc
def calculate(self):
""" Calculate something, or schedule a retry if not ready yet.
"""
if not_ready_yet:
raise Backoff()
return 42
The caller will see the final result, or a :class:`Backoff.Expired` exception if more than the allowed number of retries were made:
.. code-block:: python
>>> n.rpc.service.calculate()
... # blocks for some time
>>> 42
.. code-block:: python
>>> n.rpc.service.calculate()
Traceback (most recent call last):
...
nameko.exceptions.RemoteError: Expired Backoff aborted after ...
The retry schedule is controlled by attributes on the `Backoff` class. You should override them in a subclass to control the behaviour. For example:
Fixed schedule:
.. code-block:: python
class RegularBackoff(Backoff):
""" Retries every 1000ms until limit
"""
schedule = (1000,) # ms
No limit:
.. code-block:: python
class InfiniteBackoff(Backoff):
""" Retries forever
"""
limit = 0
Custom schedule:
.. code-block:: python
class ImpatientBackoff(Backoff):
""" Retries after 100, then 200, then 500 milliseconds
"""
schedule = (100, 200, 500) # ms
Dynamic schedule:
.. code-block:: python
class DynamicBackoff(Backoff):
""" Calculates schedule dynamically
"""
@classmethod
def get_next_schedule_item(cls, index):
...
See docs/examples for more.
=================
Extension for `nameko <http://nameko.readthedocs.org>`_ that allows the built-in AMQP entrypoints to schedule a later retry via redelivery of a message.
RabbitMQ 3.5.4 or later is required.
Installation
------------
Install the library from PyPI::
pip install nameko-amqp-retry
Usage
-----
This 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:
.. code-block:: python
from nameko_amqp_retry import Backoff
from nameko_amqp_retry.rpc import rpc
class Service:
name = "service"
@rpc
def calculate(self):
""" Calculate something, or schedule a retry if not ready yet.
"""
if not_ready_yet:
raise Backoff()
return 42
The caller will see the final result, or a :class:`Backoff.Expired` exception if more than the allowed number of retries were made:
.. code-block:: python
>>> n.rpc.service.calculate()
... # blocks for some time
>>> 42
.. code-block:: python
>>> n.rpc.service.calculate()
Traceback (most recent call last):
...
nameko.exceptions.RemoteError: Expired Backoff aborted after ...
The retry schedule is controlled by attributes on the `Backoff` class. You should override them in a subclass to control the behaviour. For example:
Fixed schedule:
.. code-block:: python
class RegularBackoff(Backoff):
""" Retries every 1000ms until limit
"""
schedule = (1000,) # ms
No limit:
.. code-block:: python
class InfiniteBackoff(Backoff):
""" Retries forever
"""
limit = 0
Custom schedule:
.. code-block:: python
class ImpatientBackoff(Backoff):
""" Retries after 100, then 200, then 500 milliseconds
"""
schedule = (100, 200, 500) # ms
Dynamic schedule:
.. code-block:: python
class DynamicBackoff(Backoff):
""" Calculates schedule dynamically
"""
@classmethod
def get_next_schedule_item(cls, index):
...
See docs/examples for more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for nameko_amqp_retry-0.1.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fcff55721b8160297fcfabe555b4384d7c2426aa30a5b72878e2c03536b27ec |
|
MD5 | b4954a5ce0d482a25419eb2131aea295 |
|
BLAKE2b-256 | 140fba5a6bbae357a7f398f4ece284abde9943fc27dbe916a2c3a93f8827d970 |