Search code examples
python-3.xcelerycelery-taskcelerybeat

Celery Beat - How to invoke a periodic task manually?


In our production environment, we have a Celery beat configured to perform periodic tasks according to the frequency.

My question is, is there a way for me to start the task that was meant to run at specific time right now?

Any advice or guidance is greatly appreciated.

I tried to add the periodic task using app.add_periodic_task from python interpreter, but it didn't work.

I am looking for some help to run any specific scheduled task at that moment either from Python interpreter or celery command line.


Solution

  • I accomplished this through following two scenarios.

    1. Connect to the related docker instance container where the Celery beat is hosted and run the below commands in Python interpreter

      from mymodule.celerybeat import cleanup cleanup.apply_async() <AsyncResult: afd71a7f-2246-4946-8572-267f3494df31>

    2. Using the Celery command line through subcommand call

      celery -A myceleryapp:app call mymodule.celerybeat.cleanup

    Note: Here myceleryapp is the app name and cleanup is the periodic task.