Y
Y
Yura Khlyan2018-09-14 14:54:46
Django
Yura Khlyan, 2018-09-14 14:54:46

What's wrong with Celery?

Good day.
I have a problem with some tasks from Celera.
Here I have such a task:

from django.core.management import call_command

from celery import shared_task


@shared_task
def send_order_review_emails():
    call_command('review_emails')

And here is the Celera config:
CELERYBEAT_SCHEDULE = {
    'send_order_review_emails': {
        'task': 'apps.catalogue.tasks.send_order_review_emails',
        'schedule': crontab(hour=5, minute=0)
    }
}

That is, the task should be performed once at 5 o'clock in the morning. But in practice it is not so:
[2018-09-14 05:00:00,044: INFO/MainProcess] Received task: apps.catalogue.tasks.send_order_review_emails[6b6335c3-0dc2-482f-b0b5-ecfd36ee06b7]
[2018-09-14 05:00:00,047: WARNING/Worker-2] Checking orders
[2018-09-14 05:00:00,056: WARNING/Worker-2] Completed.
[2018-09-14 05:00:00,057: INFO/MainProcess] Task apps.catalogue.tasks.send_order_review_emails[6b6335c3-0dc2-482f-b0b5-ecfd36ee06b7] succeeded in 0.0121419355273s: None
[2018-09-14 05:00:00,097: INFO/Beat] Scheduler: Sending due task send_order_review_emails (apps.catalogue.tasks.send_order_review_emails)
[2018-09-14 05:03:00,052: INFO/MainProcess] Received task: apps.catalogue.tasks.send_order_review_emails[8553a102-dc14-4e28-ad46-6602f9984515]
[2018-09-14 05:03:00,055: WARNING/Worker-2] Checking orders
[2018-09-14 05:03:00,066: WARNING/Worker-2] Completed.
[2018-09-14 05:03:00,066: INFO/MainProcess] Task apps.catalogue.tasks.send_order_review_emails[8553a102-dc14-4e28-ad46-6602f9984515] succeeded in 0.0133577734232s: None
[2018-09-14 05:05:00,061: INFO/MainProcess] Received task: apps.catalogue.tasks.send_order_review_emails[f67b50a9-906f-4290-9a3b-66f311295d10]
[2018-09-14 05:05:00,062: WARNING/Worker-2] Checking orders
[2018-09-14 05:05:00,073: WARNING/Worker-2] Completed.
[2018-09-14 05:05:00,073: INFO/MainProcess] Task apps.catalogue.tasks.send_order_review_emails[f67b50a9-906f-4290-9a3b-66f311295d10] succeeded in 0.0117091722786s: None
[2018-09-14 05:06:00,045: INFO/MainProcess] Received task: apps.catalogue.tasks.send_order_review_emails[543c5bc1-6f4f-475e-a254-5fd52df321ac]
[2018-09-14 05:06:00,048: WARNING/Worker-2] Checking orders
[2018-09-14 05:06:00,058: WARNING/Worker-2] Completed.
[2018-09-14 05:06:00,058: INFO/MainProcess] Task apps.catalogue.tasks.send_order_review_emails[543c5bc1-6f4f-475e-a254-5fd52df321ac] succeeded in 0.0120799578726s: None
...
[2018-09-14 05:11:00,118: INFO/MainProcess] Task apps.catalogue.tasks.send_order_review_emails[93070d02-52d6-4a61-9491-b628a7e4faa2] succeeded in 0.0735367536545s: None
[2018-09-14 05:11:12,436: INFO/Beat] Scheduler: Sending due task check_new_label (apps.dashboard.catalogue.tasks.check_new_label)
[2018-09-14 05:11:12,440: INFO/MainProcess] Received task: apps.dashboard.catalogue.tasks.check_new_label[e2b66fb3-dadd-43bb-9702-7843e318777e]
[2018-09-14 05:11:12,443: WARNING/Worker-2] Checking products
[2018-09-14 05:11:12,641: WARNING/Worker-2] Changed 0 labels
[2018-09-14 05:11:12,641: WARNING/Worker-2] Completed.
[2018-09-14 05:11:12,644: INFO/MainProcess] Task apps.dashboard.catalogue.tasks.check_new_label[e2b66fb3-dadd-43bb-9702-7843e318777e] succeeded in 0.203036315739s: None
...
[2018-09-14 05:59:00,048: INFO/MainProcess] Received task: apps.catalogue.tasks.send_order_review_emails[56f987c3-2724-40ee-8880-222451ee1094]
[2018-09-14 05:59:00,049: WARNING/Worker-2] Checking orders
[2018-09-14 05:59:00,060: WARNING/Worker-2] Completed.
[2018-09-14 05:59:00,061: INFO/MainProcess] Task apps.catalogue.tasks.send_order_review_emails[56f987c3-2724-40ee-8880-222451ee1094] succeeded in 0.0121172629297s: None
[2018-09-14 06:11:12,568: INFO/Beat] Scheduler: Sending due task check_new_label (apps.dashboard.catalogue.tasks.check_new_label)
[2018-09-14 06:11:12,571: INFO/MainProcess] Received task: apps.dashboard.catalogue.tasks.check_new_label[e8befc2f-2413-45b8-9a9f-1ba52297e467]
[2018-09-14 06:11:12,572: WARNING/Worker-2] Checking products
[2018-09-14 06:11:13,175: WARNING/Worker-2] Changed 0 labels
[2018-09-14 06:11:13,176: WARNING/Worker-2] Completed.
[2018-09-14 06:11:13,180: INFO/MainProcess] Task apps.dashboard.catalogue.tasks.check_new_label[e8befc2f-2413-45b8-9a9f-1ba52297e467] succeeded in 0.608058463782s: None

For some reason, the task is performed with an interval of 1-3 minutes. What could be the problem?
Thanks for the help.
==================================UPD=============== ==================
Just changed to dev server (Celera only there), task settings to:
'send_order_review_emails': {
        'task': 'apps.catalogue.tasks.send_order_review_emails',
        'schedule': crontab(hour=14, minute=0)
    }

And the task started only once:
[2018-09-14 13:56:00,491: INFO/Beat] beat: Starting...
[2018-09-14 13:56:00,512: INFO/MainProcess] Connected to redis+redis://socket%3A%2F%2F%2Ftmp%2Fredis.sock%3Fvirtual_host%3D1:6379//
[2018-09-14 13:56:00,526: INFO/MainProcess] mingle: searching for neighbors
[2018-09-14 13:56:01,532: INFO/MainProcess] mingle: all alone
[2018-09-14 13:56:01,540: WARNING/MainProcess] [email protected] ready.
[2018-09-14 14:00:00,065: INFO/Beat] Scheduler: Sending due task send_order_review_emails (apps.catalogue.tasks.send_order_review_emails)
[2018-09-14 14:00:00,069: INFO/MainProcess] Received task: apps.catalogue.tasks.send_order_review_emails[228f065d-51d3-4cb9-991a-84aaba49f7f4]
[2018-09-14 14:00:00,076: INFO/Beat] Scheduler: Sending due task create_supply_orders (apps.supplier_communication.tasks.create_supply_orders)
[2018-09-14 14:00:00,118: WARNING/Worker-2] Checking orders
[2018-09-14 14:00:00,131: WARNING/Worker-2] Completed.
[2018-09-14 14:00:00,141: INFO/MainProcess] Task apps.catalogue.tasks.send_order_review_emails[228f065d-51d3-4cb9-991a-84aaba49f7f4] succeeded in 0.0623154342175s: None

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vikholodov, 2018-09-14
@vikholodov

Quote from docs:

A string representing a Crontab pattern. This may get pretty advanced, like hour='*/3' (for every three hours) or hour='0.8-17/2' (at midnight, and every two hours during office hours).

I
Ivan, 2018-09-19
@VanVanuch

No offense, but are you sure that no one has set in the settings redefinition the
start for the 'apps.catalogue.tasks.send_order_review_emails' crontab(minute=3) task?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question