0

After I deploy my django project, all I need is touch uwsgi_touch file. And uwsgi will gracefully restart its workers. But what about celery? Now I just restart celery manually when code base of celery tasks is changed. But even if I do it manually I still can't be sure that I will not kill celery task.

Any solutions?

2 Answers 2

2

A better way to manage celery workers is to use supervisor

$ pip install supervisor
$ cd /path/to/your/project
$ echo_supervisord_conf > supervisord.conf

Add these to your supervisord.conf file

[program:celeryworker]
command=/path/to/celery worker -A yourapp -l info 
stdout_logfile=/path/to/your/logs/celeryd.log
stderr_logfile=/path/to/your/logs/celeryd.log

Now start supervisor with supervisord command in your terminal & use supervisorctl to manage process.

To restart you can do

$ supervisorctl restart celeryworker
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, thanks for your answer. We already use supervisor for that purpose. But the question is a bit different. I don't know how to safely deploy new version of our product. If i understand it right the celery worker and bit-scheduler need to be restarted if celery tasks was changed (code of tasks was changed). And it will be bad if i kill celery worker that process some task in production while i restarting celery.
1

I've found answer in celery FAQ http://docs.celeryproject.org/en/2.2/faq.html#how-do-i-shut-down-celeryd-safely

Use the TERM signal, and the worker will finish all currently executing jobs and shut down as soon as possible. No tasks should be lost.

You should never stop celeryd with the KILL signal (-9), unless you’ve tried TERM a few times and waited a few minutes to let it get a chance to shut down. As if you do tasks may be terminated mid-execution, and they will not be re-run unless you have the acks_late option set (Task.acks_late / CELERY_ACKS_LATE).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.