Getting Started¶
Running a function in background requires only few steps with Kuyruk. This tutorial assumes that you have a running RabbitMQ server on localhost with default configuration.
Following files and commands are in example directory for convenience.
Installing¶
Kuyruk is available on PyPI. You can install it via pip.
$ pip install kuyruk
Defining Tasks¶
Instantiate a Kuyruk
object and put a
task()
decorator on top of your function.
This will convert your function into a Task
object.
# tasks.py
from kuyruk import Kuyruk
kuyruk = Kuyruk()
@kuyruk.task()
def echo(message):
print message
You can specify some options when defining task. See
task()
for details.
Sending the Task to RabbitMQ¶
When you call the Task
object, Kuyruk will serialize the task
as JSON and will send it to a queue on RabbitMQ instead of running it.
import tasks
tasks.echo("Hello, World!")
Running a Worker¶
Run the following command to process tasks in default queue.
$ kuyruk --app tasks.kuyruk worker