I am trying to run a few functions (tasks) periodically, say every 3 seconds, with Celery.
The closest I'm getting is to just run the tasks once.
This is my Celery configuration file:
# celeryconfig.py
from datetime import timedelta
BROKER_URL = 'amqp://guest@localhost//'
CELERY_RESULT_BACKEND = 'rpc://'
CELERYBEAT_SCHEDULE = {
'f1-every-3-seconds': {
'task': 'tasks.f1',
'schedule': timedelta(seconds=3),
'args': (1, 2)
},
'f2-every-3-seconds': {
'task': 'tasks.f2',
'schedule': timedelta(seconds=3),
'args': (3, 4)
},
}
This is where I declare the tasks:
# tasks.py:
import celeryconfig
from celery import Celery
from celery import task
dbwapp = Celery('tasks')
dbwapp.config_from_object(celeryconfig)
@dbwapp.task()
def f1(a, b):
print "F1: {0}, {1}".format(a, b)
@dbwapp.task()
def f2(a, b):
print "F2: {0}, {1}".format(a, b)
And this is where my main program would run:
#tasks_runner.py:
from tasks import f1, f2, dbwapp
f1.delay(5, 6)
f2.delay(7, 8)
I run my code with: python tasks_runner.py
but don't manage to make those two functions run periodically. This is the output that I get:
[2016-03-31 23:36:16,108: WARNING/Worker-9] F1: 5, 6
[2016-03-31 23:36:16,109: WARNING/Worker-6] F2: 7, 8
What am I doing wrong? How do I make f1 and f2 to run periodically?