/redbeat-example

An example of Dynamic Task Scheduling using the RedBeat python package, and Celery Beat.

Primary LanguagePythonMIT LicenseMIT

CeleryBeat with RedBeatScheduler

A short example of how to run a RedBeatScheduler over CeleryBeat. It will require two terminal windows to run:

$ celery worker -A cluster -l info -P eventlet
$ celery beat -A cluster -l info

Then in a third window:

$ python
>>> import cluster
>>> from redbeat import RedBeatSchedulerEntry as Entry
>>> e = Entry('thingo', 'cluster.add_task', 10, args=[15, 4], app=cluster.app)
>>> e.save()
>>> key = e.key()

You should see log entries generated by the cluster.add_task method in your celery worker terminal. This indicates that it is working. You can also remove the task:

>>> import cluster
>>> from redbeat import RedBeatSchedulerEntry as Entry
>>> e = Entry.from_key(key)  # whatever the key was before
>>> e.delete()

and you should no longer see log entries (as the worker is no longer receiving tasks from the scheduler). Of course, you should have some method of keeping track of the keys for tasks you have scheduled, but I leave that to you (DB, file, etc).

Hope this helps somebody :)