简体   繁体   中英

How to set periodic task on Django using celery?

My current code:

from celery.task.schedules import crontab
from celery.decorators import task, periodic_task


@periodic_task(run_every=crontab(hour=15, minute=55, day_of_week="wed"))
def demo():
    print("testing------------------------")

Setting file:

CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'amqp://guest:guest@localhost//')

It's not working, am I missing something?

Thanks In advance

I think you should use the below code, it should be work for you.

celery_app = celery("project_name")

@celery_app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
  sender.add_periodic_task(5.0, demo.s(args))

@celery_app.task(bind=True)
def demo(args):
   print("testing------------------------")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM