Reputation: 29805
I have installed celery using redis on a centos linux server.
I start a celery worker using the following command:
celery multi start worker1 -A proj -Q lopri,lopri2 -l info --pidfile="$HOME/run/celery/%n.pid" --logfile="$HOME/log/celery/%n.log"
The problem is that after a few hours, the worker no longer responds task creation. I have to restart the worker in order for it to process tasks again.
Here is the celery settings file located at /etc/default/celeryd:
# Names of nodes to start
# most people will only start one node:
CELERYD_NODES="worker1"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS (see `celery multi --help` for examples):
#CELERYD_NODES="worker1 worker2 worker3"
# alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=10
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="proj"
# or fully qualified:
#CELERY_APP="proj.tasks:app"
#django settings
#export DJANGO_SETTINGS_MODULE="settings"
# Where to chdir at start.
CELERYD_CHDIR="/var/www/html/proj/"
# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# %N will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"
# Workers should run as an unprivileged user.
# You need to create this user manually (or you can choose
# a user/group combination that already exists, e.g. nobody).
CELERYD_USER="ec2-user"
CELERYD_GROUP="ec2-user"
# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1
One problem that maybe a clue as to what is happening is that I have to run the "start" command from the project folder other wise I receive the error:
ImportError: No module named proj
Shouldn't the CELERYD_CHDIR
setting take care of this? Does that mean that my start command is not using this celery default setting file?
Thanks for any light you can shed on this.
Upvotes: 0
Views: 1293
Reputation: 46
If you are running celery by command line, your settings file is pretty much useless. I mean, they are not being applied, that's why you get an error saying your project can't be imported.
This is the script to run celery as daemon: https://github.com/celery/celery/blob/3.1/extra/generic-init.d/celeryd
As you can see here: https://github.com/celery/celery/blob/3.1/extra/generic-init.d/celeryd#L56 That's where the script imports your settings.
I'm not quite sure why your celeryd stops working after a few hours, but this shows that's you're not really running as a daemon. Maybe setting the propert init.d script with settings can fix that, but I doubt it.
Upvotes: 2