django - How to restart Celery gracefully without delaying tasks -


we use celery our django webapp manage offline tasks; of these tasks can run 120 seconds.

whenever make code modifications, need restart celery have reload new python code. our current solution send sigterm main celery process (kill -s 15 `cat /var/run/celeryd.pid`), wait die , restart (python manage.py celeryd --pidfile=/var/run/celeryd.pid [...]).

because of long-running tasks, means shutdown take minute or two, during no new tasks processed, causing noticeable delay users on site. i'm looking way tell celery shutdown, launch new celery instance start running new tasks.

things didn't work:

  • sending sighup main process: caused celery attempt "restart," doing warm shutdown , relaunching itself. not take long time, doesn't work, because apparently new process launches before old 1 dies, new 1 complains error: pidfile (/var/run/celeryd.pid) exists. seems we're running? (pid: 13214) , dies immediately. (this looks bug in celery itself; i've let them know it.)
  • sending sigterm main process , launching new instance: same issue pidfile.
  • disabling pidfile entirely: without it, have no way of telling of 30 celery process main process needs sent sigterm when want warm shutdown. have no reliable way check if main process still alive.

celeryd has --autoreload option. if enabled, celery worker (main process) detect changes in celery modules , restart worker processes. in contrast sighup signal, autoreload restarts each process independently when current executing task finishes. means while 1 worker process restarting remaining processes can execute tasks.

http://celery.readthedocs.org/en/latest/userguide/workers.html#autoreloading


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -