We have a periodic celery task

 @periodic_task(run_every=crontab(hour=6)) def task(): pass 

We start this task every morning at 6 o'clock in the morning. We start the task logging.

A couple of days passed, we expect to see TWO lines in the logs.

But celery started this task 20 times. Weighed a bunch of loggers, screwed the sentry , simplified the task to a minimum, but the task continues to run in the wrong way.

What could be the problem?

Expected behavior described.

The command to start the worker:

celery -A project worker -B --loglevel=info --logfile=./logs/celery.log

  • one
    Is the worker exactly running exactly once? - andreymal
  • @andreymal yes. The same behavior both on LAN and prod (use docker). Without docker on LAN the same trouble. - Ivan Blohin
  • one
    So stop, if I understand the documentation correctly, the crontab is by default set to every minute - try to explicitly set the minutes to zero - andreymal
  • @andreymal if that were the case, the task would run every minute. And as if we were launching a pack of tasks, instead of two. As if there are more such tasks in the task queue. Also tried on LAN to run every 38, 40, 45 minutes and so on for debug - also not obvious behavior. - Ivan Blohin
  • one
    Then the guesses are still over, personally my celery works fine. Nevertheless, in the text of the question, write the minute explicitly so that there are no unnecessary questions from other users - andreymal

1 answer 1

Decision:

 @periodic_task(run_every=crontab(hour=6, minute=0)) def task(): pass 

(Added minute=0 ).

I apologize to @andreymal . checked his theory in action just now. Were sure that if the problem was in a minute, the tasks would run every minute.

In general, the strange behavior was decided exactly as we were advised to try - add minute=0 .