51👍
According to https://docs.celeryq.dev/en/stable/userguide/workers.html#restarting-the-worker you can restart a worker by sending a HUP signal
ps auxww | grep celeryd | grep -v "grep" | awk '{print $2}' | xargs kill -HUP
15👍
celery multi start 1 -A proj -l info -c4 --pidfile=/var/run/celery/%n.pid
celery multi restart 1 --pidfile=/var/run/celery/%n.pid
http://docs.celeryproject.org/en/latest/userguide/workers.html#restarting-the-worker
- [Django]-How can I check the size of a collection within a Django template?
- [Django]-'EntryPoints' object has no attribute 'get' – Digital ocean
- [Django]-Django admin, hide a model
8👍
- [Django]-'pip' is not recognized as an internal or external command
- [Django]-Django TemplateDoesNotExist?
- [Django]-Auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'UserManage.groups'
6👍
If you’re going the kill
route, pgrep to the rescue:
kill -9 `pgrep -f celeryd`
Mind you, this is not a long-running task and I don’t care if it terminates brutally. Just reloading new code during dev. I’d go the restart service route if it was more sensitive.
- [Django]-PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django
- [Django]-How to send email via Django?
- [Django]-Why is using thread locals in Django bad?
- [Django]-How to redirect with post data (Django)
- [Django]-How to annotate Count with a condition in a Django queryset
- [Django]-Running django tutorial tests fail – No module named polls.tests
2👍
What should happen to long running tasks? I like it this way: long running tasks should do their job. Don’t interrupt them, only new tasks should get the new code.
But this is not possible at the moment: https://groups.google.com/d/msg/celery-users/uTalKMszT2Q/-MHleIY7WaIJ
- [Django]-Django 1.5 – How to use variables inside static tag
- [Django]-Effects of changing Django's SECRET_KEY
- [Django]-How to customize activate_url on django-allauth?
2👍
I have repeatedly tested the -HUP solution using an automated script, but find that about 5% of the time, the worker stops picking up new jobs after being restarted.
A more reliable solution is:
stop <celery_service>
start <celery_service>
which I have used hundreds of times now without any issues.
From within Python, you can run:
import subprocess
service_name = 'celery_service'
for command in ['stop', 'start']:
subprocess.check_call(command + ' ' + service_name, shell=True)
- [Django]-No module named MySQLdb
- [Django]-Why doesn't django's model.save() call full_clean()?
- [Django]-__init__() got an unexpected keyword argument 'mimetype'
0👍
If you’re using docker/docker-compose and putting celery into a separate container from the Django container, you can use
docker-compose kill -s HUP celery
, where celery is the container name. The worker will be gracefully restarted and the ongoing task is not brutally stopped.
Tried pkill, kill, celery multi stop, celery multi restart, docker-compose restart. All not working. Either the container is stopped abruptly or the code is not reloaded.
I just want to reload my code in the prod server manually with a 1-liner. Don’t want to play with daemonization.
- [Django]-No module named urllib.parse (How should I install it?)
- [Django]-How to disable Django's invalid HTTP_HOST error?
- [Django]-Django-cors-headers not work
-3👍
Might be late to the party. I use:
sudo systemctl stop celery
sudo systemctl start celery
sudo systemctl status celery
- [Django]-Django manage.py runserver invalid syntax
- [Django]-What is the default order of a list returned from a Django filter call?
- [Django]-How do I install an old version of Django on virtualenv?