Running the server

Run django-ztask using the manage.py command:

python manage.py ztaskd

Command-line arguments

The ztaskd command takes a series of command-line arguments:

--noreload

By default, ztaskd will use the built-in Django reloader
to reload the server whenever a change is made to a python file. Passing
in --noreload will prevent it from listening for changed files.
(Good to use in production.)

-l or --loglevel

Choose from the standard CRITICAL, ERROR, WARNING,
INFO, DEBUG, or NOTSET. If this argument isn't passed
in, INFO is used by default.

-f or --logfile

The file to log messages to. By default, all messages are logged
to stdout

--replayfailed

If a command has failed more times than allowed in the
ZTASKD_RETRY_COUNT (see below for more), the task is
logged as failed. Passing in --replayfailed will cause all
failed tasks to be re-run.

Settings

There are several settings that you can put in your settings.py file in
your Django project. These are the settings and their defaults

ZTASKD_URL = 'tcp://127.0.0.1:5555'

By default, ztaskd will run over TCP, listening on 127.0.0.1 port 5555.

ZTASKD_ALWAYS_EAGER = False

If set to True, all .async and .after tasks will be run in-process and
not sent to the ztaskd process. Good for task debugging.

ZTASKD_DISABLED = False

If set, all tasks will be logged, but not executed. This setting is often
used during testing runs. If you set ZTASKD_DISABLED before running
python manage.py test, tasks will be logged, but not executed.

ZTASKD_RETRY_COUNT = 5

The number of times a task should be reattempted before it is considered failed.

ZTASKD_RETRY_AFTER = 5

The number, in seconds, to wait in-between task retries.

ZTASKD_ON_LOAD = ()

This is a list of callables - either classes or functions - that are called when the server first
starts. This is implemented to support several possible Django setup scenarios when launching
ztask - for an example, see the section below called Implementing with Johnny Cache.

Running in production

A recommended way to run in production would be to put something similar to
the following in to your rc.local file. This example has been tested on
Ubuntu 10.04 and Ubuntu 10.10:

Implementing with Johnny Cache

Because Johnny Cache monkey-patches all the Django query compilers,
any changes to models in django-ztask that aren't properly patched won't reflect on your site until the cache
is cleared. Since django-ztask doesn't concern itself with Middleware, you must put Johnny Cache's query cache
middleware in as a callable in the ZTASKD_ON_LOAD setting.

ZTASKD_ON_LOAD = (
'johnny.middleware.QueryCacheMiddleware',
...
)

If you wanted to do this and other things, you could write your own function, and pass that in to
ZTASKD_ON_LOAD, as in this example:

myutilities.py

def ztaskd_startup_stuff():
'''
Stuff to run every time the ztaskd server
is started or reloaded
'''
from johnny import middleware
middleware.QueryCacheMiddleware()
... # Other setup stuff