Skip to main content

Queue management and code deferment

Project description

What is engine?

engine is a collection of tools for processing a queue. It provides an API to defer a callable and run it later. engine also provides process helpers to set up a safe environment for clearing different kind of queues.

How to use engine?

The basic usage of engine is to defer something to execute later. However, the internals are written in such way to allow for planning. You can plan your code to use a queue, but a queue doesn’t even need to be present. Lets take a look at an example:

>>> import engine
>>> def hello_world():
...     print "hello world"

>>> engine.defer(hello_world)
hello world

As you can see above, the function hello_world was executed immediately. This is because, by default, engine will use the DummyQueue which will execute the given callable when put on the queue.

If you have a queue such as stompserver, ActiveMQ or any STOMP compliant queue you can use StompQueue. Lets take a look at an example:

>>> import engine
>>> def hello_world():
...     print "hello world"

>>> engine.defer(hello_world, queue=engine.StompQueue())

The above code will now defer the call to hello_world by sending it to the queue.

You can define the default queue used by engine. To do this you should use engine.configure. Here is an example changing the default queue from DummyQueue to StompQueue:

>>> import engine
>>> engine.configure(queue=engine.StompQueue())

Now all calls to engine.defer will use the StompQueue instance.

Project details

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page