Question

I am just getting started with celery,trying to run a periodic task.

Configured *rabbitmq** added celeryconfig.py.

And added following code in tasks.py:

from celery.decorators import periodic_task
from datetime import timedelta

@periodic_task(run_every=timedelta(seconds=2))
def every_2_seconds():
    print("Running periodic task!")

Now when I start celerybeat by typing "celerybeat" in my terminal it starts to run with follwing message

celerybeat 
celerybeat v3.0.3 (Chiastic Slide) is starting.
__    -    ... __   -        _
Configuration ->
    . broker -> amqp://arnold@localhost:5672//
    . loader -> celery.loaders.default.Loader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> celerybeat-schedule
    . logfile -> [stderr]@INFO
    . maxinterval -> now (0s)
[2012-08-03 14:24:52,202: INFO/MainProcess] Celerybeat: Starting...

And there is no output of every_2_seconds method in the terminal.I am assuming I have to specify which app to run or wich tasks during the celerybeat command.How to do that?

How can I specify tasks and print the line after every 2 seconds as a periodic tasks?

Thanks.

Was it helpful?

Solution

Add CELERY_IMPORTS=("tasks",) to your celeryconfig.py then run celerybeat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top