Skip to content

Celerybeat runs periodic tasks every 5 seconds regardless of interval #943

Closed

Description

@thongly

I recently upgraded to celery 3 and have been experiencing some strange behavior with celerybeat, which was acting normally before the upgrade.

My environment:

python 2.7.3
django 1.4.1
virtualenv
django-celery 3.0.6
celery 3.0.6

Regardless of what interval I define for my periodic tasks - which I adjust through the django admin - celerybeat fires off the periodic tasks every 5 seconds. This occurs regardless of the interval. Interestingly, however, when the periodic task is set disabled, celerybeat stops sending tasks, so it must be responsive to the scheduler at some level.

Activity

  1. ask commented on Aug 28, 2012

    @ask
    Contributor

    Could you try upgrading to celery 3.0.7? Also please delete an existing celerybeat-schedule file if any.

  2. thongly commented on Aug 28, 2012

    @thongly
    Author

    Thanks - Will try that and update later today.

    On Tue, Aug 28, 2012 at 12:02 PM, Ask Solem Hoel
    [email protected]:

    Could you try upgrading to celery 3.0.7? Also please delete an existing
    celerybeat-schedule file if any.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/943#issuecomment-8096911.

  3. erikcw commented on Aug 29, 2012

    @erikcw

    I'm having the same problem on 3.0.7 (django-celery 3.0.6), redis broker.

    from celery.task import periodic_task
    
    @periodic_task(run_every=crontab(hour="*", minute="0", day_of_week="*"), ignore_result=True)
    def my_test():
        pass
    
  4. thongly commented on Aug 29, 2012

    @thongly
    Author

    Just to confirm - I have installed celery 3.0.7 now (although django-celery
    is still 3.0.6) and am still having the same issues. I am also using Redis
    as a broker.

    I have even dropped the DB, in case it was something caused by my south
    migrations, yet the problem still persists.

    Please let me know if you'd like me to try anything else.

    On Tue, Aug 28, 2012 at 9:38 PM, erikcw [email protected] wrote:

    I'm having the same problem on 3.0.7 (django-celery 3.0.6), redis broker.

    from celery.task import periodic_task

    @periodic_task(run_every=crontab(hour="", minute="0", day_of_week=""), ignore_result=True)
    def my_test():
    pass

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/943#issuecomment-8112944.

  5. thongly commented on Aug 30, 2012

    @thongly
    Author

    I have upgraded to 3.0.8 and the problem still occurs. Issue should be reopened.

  6. ask commented on Aug 30, 2012

    @ask
    Contributor

    Note, anyone using the database scheduler have to reset the last_run_at fields for each periodic task:

    $ python manage.py shell
    
    >>> from djcelery.models import PeriodicTask
    >>> PeriodicTask.objects.update(last_run_at=None)
    
  7. ju-popov commented on Oct 2, 2012

    @ju-popov

    I have a task scheduled for 04:00 AM and found that it's executed 2151 times (every 5 seconds) from 07:00 АМ. to 10:00 АМ and then it stops. Time here is GMT+3

    Also:
    python 2.7.3
    django 1.4.1 (USE_TZ = True)
    virtualenv
    django-celery 3.0.6
    celery 3.0.6

    last_run_at is None

  8. ju-popov commented on Nov 29, 2012

    @ju-popov

    Has anyone with similar problem?

  9. grigoriytretyakov commented on Jun 10, 2015

    @grigoriytretyakov

    I have one. But in my case task runs every 5 minutes instead of run once a day.

    Python3.4
    celery==3.1.17
    Django==1.8
    

    settings.py:

    from celery.schedules import crontab
    
    USE_TZ = True
    TIME_ZONE = 'Europe/Moscow'
    
    CELERY_ENABLE_UTC = False
    CELERY_TIMEZONE = TIME_ZONE
    
    CELERYBEAT_SCHEDULE = {
        'every-day': {
            'task': 'app.tasks.every_day',
            'schedule': crontab(minute=30, hour=0),
        },
    }
    

    Celery works under supervisord:

    celery worker -A proj -l info --concurrency=2 -Ofair
    celery beat -A proj  -l info
    

    After 00:30 at midnight Celery sends task first time and then keep firing it until 03:30.

  10. thedrow commented on Jun 14, 2015

    @thedrow
    Contributor

    I'm reopening this issue due to @monax's report.
    Can you please provide steps to reproduce?

  11. grigoriytretyakov commented on Jun 15, 2015

    @grigoriytretyakov

    @thedrow Wait a couple of days, please. I'll try to make mini project to reproduce issue.

  12. thedrow commented on Jun 15, 2015

    @thedrow
    Contributor

    Wonderful! thanks.

  13. grigoriytretyakov commented on Jun 15, 2015

    @grigoriytretyakov

    https://github.com/monax/celeryissue

    In repo there is requirements.txt with all dependencies. As a broker I use rabbitmq.

    In settings.py there is a code which schedules a task to next minute after start.

    from celery.schedules import crontab
    from datetime import datetime
    
    USE_TZ = True
    TIME_ZONE = 'Europe/Moscow'
    
    CELERY_ENABLE_UTC = False
    CELERY_TIMEZONE = TIME_ZONE
    
    t = datetime.today()
    ONE_MINUTE_AFTER = crontab(minute=t.minute + 1, hour=t.hour)
    
    CELERYBEAT_SCHEDULE = {
        'every-day': {
            'task': 'apptask.tasks.every_day',
            'schedule': ONE_MINUTE_AFTER,
        },
    }
    

    Create a new virtualenv using pyvenv (python 3.4.3). Install requirements.txt and run in two terminals:

    celery worker -A celeryissue -l info --concurrency=2 -Ofair
    
    celery beat -A celeryissue  -l info
    

    For beat you'll see:

    celery beat -A celeryissue  -l info                  
    celery beat v3.1.17 (Cipater) is starting.
    __    -    ... __   -        _
    Configuration ->
        . broker -> amqp://guest:**@localhost:5672//
        . loader -> celery.loaders.app.AppLoader
        . scheduler -> celery.beat.PersistentScheduler
        . db -> celerybeat-schedule
        . logfile -> [stderr]@%INFO
        . maxinterval -> now (0s)
    [2015-06-15 12:35:50,911: INFO/MainProcess] beat: Starting...
    [2015-06-15 12:36:00,000: INFO/MainProcess] Scheduler: Sending due task every-day (apptask.tasks.every_day)
    [2015-06-15 12:41:00,103: INFO/MainProcess] Scheduler: Sending due task every-day (apptask.tasks.every_day)
    [2015-06-15 12:46:00,193: INFO/MainProcess] Scheduler: Sending due task every-day (apptask.tasks.every_day)
    
    

    For worker you'll see something like that:

    [2015-06-15 12:36:00,009: INFO/MainProcess] Received task: apptask.tasks.every_day[c23dd76b-1181-4115-9379-d04e69879c49]
    [2015-06-15 12:36:00,013: INFO/Worker-2] Fire: 2015-06-15 12:36:00.013325
    [2015-06-15 12:36:00,015: INFO/MainProcess] Task apptask.tasks.every_day[c23dd76b-1181-4115-9379-d04e69879c49] succeeded in 0.0025641939992055995s: None
    [2015-06-15 12:41:00,106: INFO/MainProcess] Received task: apptask.tasks.every_day[2d746b9e-4b83-421b-8cde-a75f6a537fc1]
    [2015-06-15 12:41:00,108: INFO/Worker-1] Fire: 2015-06-15 12:41:00.108269
    [2015-06-15 12:41:00,110: INFO/MainProcess] Task apptask.tasks.every_day[2d746b9e-4b83-421b-8cde-a75f6a537fc1] succeeded in 0.0021385390009527327s: None
    [2015-06-15 12:46:00,196: INFO/MainProcess] Received task: apptask.tasks.every_day[8487f014-98f2-444a-91da-36621a5e7edc]
    [2015-06-15 12:46:00,198: INFO/Worker-2] Fire: 2015-06-15 12:46:00.197949
    [2015-06-15 12:46:00,198: INFO/MainProcess] Task apptask.tasks.every_day[8487f014-98f2-444a-91da-36621a5e7edc] succeeded in 0.0014146600005915388s: None
    
  14. thedrow commented on Jun 15, 2015

    @thedrow
    Contributor

    I'll run it and let you know.

  15. 9 remaining items

  16. shtalinberg commented on Nov 1, 2017

    @shtalinberg

    I also have this problem with django 1.10.8 and celery==4.1.0 without django-celery-beat

    CELERY_ENABLE_UTC = False
    CELERY_TIMEZONE = 'Europe/Kiev'

    but if I set CELERY_ENABLE_UTC = False and NOT set CELERY_TIMEZONE - all work fine without timezone
    Problem only with CELERY_ENABLE_UTC = False and set CELERY_TIMEZONE

  17. thedrow commented on Nov 1, 2017

    @thedrow
    Contributor

    I released a new version of django-celery-beat. Can you please try again?
    If there's still a problem please open a new issue.

  18. shtalinberg commented on Nov 1, 2017

    @shtalinberg

    I have this problem without django-celery-beat

  19. rollue commented on Nov 6, 2017

    @rollue
  20. vascubrian commented on Feb 16, 2018

    @vascubrian

    Flask I am having problem

  21. vascubrian commented on Feb 16, 2018

    @vascubrian

    from celery.schedules import crontab

    CELERY_TASK_RESULT_EXPIRES = 30
    CELERY_TIMEZONE = 'Africa/Nairobi'

    CELERY_ACCEPT_CONTENT = ['json', 'msgpack', 'yaml']
    CELERY_TASK_SERIALIZER = 'json'
    CELERY_RESULT_SERIALIZER = 'json'

    CELERYBEAT_SCHEDULE = {
    'test-celery': {
    'task': 'execute_celery.sendSms',
    # Every minute
    'schedule': crontab(minute="*"),
    }
    }

  22. vascubrian commented on Feb 16, 2018

    @vascubrian

    how to run above things

  23. auvipy commented on Feb 17, 2018

    @auvipy
    Member

    instal django celery beat from github master

  24. Tur8008 commented on Apr 13, 2018

    @Tur8008

    Hello. I'm using celery == 4.0.1 and django-celery-beat==1.1.1 with django == 2.0.3.
    I have the same problem if CELERY_TIME_ZONE option is given. If I don't do this - everything is ok, but I have problem with execution time of my task.

  25. rinkuameotech commented on Feb 4, 2019

    @rinkuameotech

    I am having the same issue it is firing the task every second
    I am using celery == 4.2.1 and django-celery-beat==1.1.1 with django==1.11

  26. andodet commented on May 11, 2020

    @andodet

    I am having a very similar problem in Flask. The task gets executed every 10 seconds, ignoring the crontab schedule altoghether.
    Environment info:

    Flask==1.1.2
    celery==4.4.2
    

    The crontab schedule is specified, alongside other Celery settings, in the following way in my config.py file:

    CELERY_IMPORTS = ["app.tasks"]
    CELERY_BROKER_URL = 'redis://:devpassword@redis:6379/0'
    CELERY_RESULT_BACKEND = 'redis://:devpassword@redis:6379/0'
    CELERY_ACCEPT_CONTENT = ['json']
    CELERY_TASK_SERIALIZER = 'json'
    CELERY_RESULT_SERIALIZER = 'json'
    CELERYBEAT_SCHEDULE = {
        "check_istop_hourly": {
            "task": "tasks.update_is_top",
            "schedule": crontab(hour="*", minute="1"),
            "args": ()  
        }
    }

    When the container starts, the task frequency is set to 10 seconds

    celery_1  | [2020-05-11 08:56:23,843: DEBUG/Beat] Current schedule:
    celery_1  | <ScheduleEntry: app.tasks.update_is_top() app.tasks.update_is_top() <freq: 10.00 seconds
    

    Notice that no timezone has been declared

  27. smyja commented on May 15, 2022

    @smyja

    Ff

    I am having a very similar problem in Flask. The task gets executed every 10 seconds, ignoring the crontab schedule altoghether. Environment info:

    Flask==1.1.2
    celery==4.4.2
    

    The crontab schedule is specified, alongside other Celery settings, in the following way in my config.py file:

    CELERY_IMPORTS = ["app.tasks"]
    CELERY_BROKER_URL = 'redis://:devpassword@redis:6379/0'
    CELERY_RESULT_BACKEND = 'redis://:devpassword@redis:6379/0'
    CELERY_ACCEPT_CONTENT = ['json']
    CELERY_TASK_SERIALIZER = 'json'
    CELERY_RESULT_SERIALIZER = 'json'
    CELERYBEAT_SCHEDULE = {
        "check_istop_hourly": {
            "task": "tasks.update_is_top",
            "schedule": crontab(hour="*", minute="1"),
            "args": ()  
        }
    }

    When the container starts, the task frequency is set to 10 seconds

    celery_1  | [2020-05-11 08:56:23,843: DEBUG/Beat] Current schedule:
    celery_1  | <ScheduleEntry: app.tasks.update_is_top() app.tasks.update_is_top() <freq: 10.00 seconds
    

    Notice that no timezone has been declared

    Did you resolve it?

  28. thedrow commented on May 16, 2022

    @thedrow
    Contributor

    Yes, long time ago. Please upgrade to the latest Celery version.

  29. melgart commented on Apr 21, 2023

    @melgart

    @thedrow Can you please let us know which specific Celery version this was fixed in? 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions