Reputation: 36414
This is my periodic task:
from celery.task import PeriodicTask
from celery.registry import tasks
from datetime import timedelta
from datetime import datetime
class MyTask(PeriodicTask):
run_every = timedelta(minutes=1)
def run(self, **kwargs):
self.get_logger().info("Time now: " + datetime.now())
print("Time now: " + datetime.now())
tasks.register(MyTask)
I started my django server at python manage.py runserver and also started celery with python manage.py celeryd -B.
Still nothing gets printed on the command prompt though according to the code, the time should have been printed.
Any idea what's going wrong here? Seems quite straight forward.
Upvotes: 3
Views: 1993
Reputation: 5817
Check your system time-zone if is the same as Django time zone.
For Django: Change it from settings file.
For linux operating system: change it like that: ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime
Upvotes: 0
Reputation: 2932
You should have something like:
CELERYBEAT_SCHEDULE = {
'proc': {
"task": "tasks.processing",
"schedule": timedelta(seconds=60),
},
}
in your celeryconfig.py
or in django's settings.py
See full documentaion here http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html
Upvotes: 1