Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to continue executing celery queue after stopping Redis and then starting it later?

I am running a Django application that runs asynchronous tasks using Celery and using a Redis server as a worker.

I need to be able to stop the entire infrastructure and bring it back up without causing a break in the execution of tasks. So I need to do this:

1) Stop the Django webservice
2) Stop celery
3) Shut down Redis daemon
4) Make a few changes in the server or move to a different machine
5) Start Redis daemon
6) Start Celery
7) Start the Django webservice

When the entire infrastructure is back up again it should continue where it left off. i.e. if there were any tasks in the queue it should continue executing them.

How do I go about doing this? Is there a way to save the queue and continue later?

like image 777
Vinay Avatar asked May 11 '20 07:05

Vinay


1 Answers

Is there a way to save the queue and continue later?

Yes. All your tasks are saved in Redis. If you can keep it running, or export/import its data you won't lose any tasks.

So broadly 2 options.

Option 1:

  1. Stop the Django webservice
  2. Stop celery
  3. Export redis data to a snapshot using RDB
  4. Shut down Redis daemon
  5. Make a few changes in the server or move to a different machine
  6. Start Redis daemon
  7. Import redis data from the snapshot
  8. Start Celery
  9. Start the Django webservice

More on RDB: https://redis.io/topics/persistence

Option 2:

  1. Stop the Django webservice
  2. Stop celery
  3. Make a few changes in the server or move to a different machine
  4. Start Celery
  5. Start the Django webservice

All the while keeping redis running.

like image 104
Vedant Agarwala Avatar answered Oct 23 '22 05:10

Vedant Agarwala