celerybeat - multiple instances & monitoring

前端 未结 3 1854
长情又很酷
长情又很酷 2021-02-05 21:15

I\'m having application built using celery and recently we got a requirement to run certain tasks on schedule.

I think celerybeat is perfect for this, but I got few ques

3条回答
  •  太阳男子
    2021-02-05 21:46

    You may run multiple instances of celery beat and tasks will not be duplicated.

    Take a look at the celery.beat.Scheduler class, specifically the reserve() function. The scheduler will reserve a task before submitting it to the grid for execution. This prevents another instance of celery beat from submitting the same task.

    We use MongoDB as a backing store for our scheduled tasks. Here is a sample document showing that the task has been reserved by one of the schedulers.

    {
      "startdate": "2015-07-06 00:00:00", 
      "task": "cobalt.grid.tasks_facts.task_add", 
      "enddate": "2018-01-01 00:00:00", 
      "args": "[13.0, 42.0]", 
      "enabled": "True", 
      "last_run_at": "2015-08-13 15:04:49.058000", 
      "interval": "{u'every': u'1', u'period': u'minutes'}", 
      "relative": "False", 
      "total_run_count": "12", 
      "kwargs": "{}", 
      "reserved": "compute2:25703", 
      "_id": "ObjectId(55ccaf7784a3e752e73b08c2)", 
      "options": "{}"
    }
    

    http://celery.readthedocs.org/en/latest/reference/celery.beat.html#celery.beat.Scheduler

提交回复
热议问题