2017-06-01 21 views
1

我把芹菜的crontab像下面芹菜拍:crontab中執行相同的任務兩次(間隔10分鐘)

Proj_root /凸出/ celery.py

app.conf.update(
    CELERYBEAT_SCHEDULE={ 
     'do_every_1st_day_of_month': { 
      'task': 'foobar', 
      'schedule': crontab(0, 0, day_of_month='1'), 
      'args':() 
     }, 
    }) 

但最後它被執行了兩次, 2017/05/31 23:50:00和2017/06/01 00:00:00。

我找不到理由。 根據crontab參數,它不應該在2017/05/31完成。

爲什麼這樣?這是當時的相關日誌。 如果需要項目的另一部分,我會申請後

[2017-05-31 23:50:00,002: INFO/Beat] Scheduler: Sending due task (foobar) 
[2017-05-31 23:50:00,004: DEBUG/Beat] foobar sent. id->8240fb96-994c-4f96-bf4d-4824f0e0c407 
[2017-05-31 23:50:00,005: DEBUG/Beat] beat: Waking up in 5.00 minutes. 
[2017-05-31 23:50:00,005: INFO/MainProcess] Received task: foobar[8240fb96-994c-4f96-bf4d-4824f0e0c407] 
[2017-05-31 23:50:00,006: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x80740b1e0> (args:('foobar', '8240fb96-994c-4f96-bf4d-4824f0e0c407', {'lang': 'py', 'task': 'foobar', 'id': '8240fb96-994c-4f96-bf4d-4824f0e0c407', 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': '8240fb96-994c-4f96-bf4d-4824f0e0c407', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': '{}', 'origin': '[email protected]', 'reply_to': '257ab156-57fa-3806-bdf1-28d5501b0472', 'correlation_id': '8240fb96-994c-4f96-bf4d-4824f0e0c407', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}}, b'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]', 'application/json', 'utf-8') kwargs:{}) 
[2017-05-31 23:50:00,006: DEBUG/MainProcess] Task accepted: foobar[8240fb96-994c-4f96-bf4d-4824f0e0c407] pid:63838 
[2017-05-31 23:50:00,789: INFO/PoolWorker-4] Task foobar[8240fb96-994c-4f96-bf4d-4824f0e0c407] succeeded in 0.7823948785662651s: None 
[2017-05-31 23:55:00,006: DEBUG/Beat] beat: Synchronizing schedule... 
[2017-05-31 23:55:00,007: DEBUG/Beat] beat: Waking up in 5.00 minutes. 
[2017-05-31 23:59:59,991: DEBUG/Beat] beat: Synchronizing schedule... 
[2017-06-01 00:00:00,001: INFO/Beat] Scheduler: Sending due task do_every_1st_day_of_month (foobar) 
[2017-06-01 00:00:00,004: DEBUG/Beat] foobar sent. id->6da824e0-14bf-4e56-a279-bdc2d466ab1e 
[2017-06-01 00:00:00,006: INFO/MainProcess] Received task: foobar[6da824e0-14bf-4e56-a279-bdc2d466ab1e] 
[2017-06-01 00:00:00,006: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x80740b1e0> (args:('foobar', '6da824e0-14bf-4e56-a279-bdc2d466ab1e', {'lang': 'py', 'task': 'foobar', 'id': '6da824e0-14bf-4e56-a279-bdc2d466ab1e', 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': '6da824e0-14bf-4e56-a279-bdc2d466ab1e', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': '{}', 'origin': '[email protected]', 'reply_to': '257ab156-57fa-3806-bdf1-28d5501b0472', 'correlation_id': '6da824e0-14bf-4e56-a279-bdc2d466ab1e', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}}, b'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]', 'application/json', 'utf-8') kwargs:{}) 
[2017-06-01 00:00:00,010: DEBUG/MainProcess] Task accepted: foobar[6da824e0-14bf-4e56-a279-bdc2d466ab1e] pid:63838 
[2017-06-01 00:00:00,615: INFO/PoolWorker-4] Task foobar[6da824e0-14bf-4e56-a279-bdc2d466ab1e] succeeded in 0.6074081044644117s: None 

*編輯2017年6月5日

我發現了一些奇怪的事情 我看着芹菜日誌,有一個多任務運行間隔的兩倍10分鐘。 它在預定時間之前運行10分鐘。並且還執行準確的預定時間。

<ScheduleEntry: do-bar-every-midnight bar() <crontab: 0 23 * * * (m/h/d/dM/MY)> 

... 

[2017-05-31 01:33:43,324: DEBUG/Beat] beat: Ticking with max interval->5.00 minutes 
[2017-05-31 22:50:00,002: INFO/Beat] Scheduler: Sending due task do-bar-every-midnight (bar) 
[2017-05-31 22:50:00,003: DEBUG/Beat] bar sent. id->cf9c0268-3071-418a-be60-c7dee75c973b 
[2017-05-31 22:50:00,004: DEBUG/Beat] beat: Waking up in 5.00 minutes. 
[2017-05-31 22:50:00,005: INFO/MainProcess] Received task: bar[cf9c0268-3071-418a-be60-c7dee75c973b] 
[2017-05-31 22:50:00,006: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x80740b1e0> (args:('bar', 'cf9c0268-3071-418a-be60-c7dee75c973b', {'lang': 'py', 'task': 'bar', 'id': 'cf9c0268-3071-418a-be60-c7dee75c973b', 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'cf9c0268-3071-418a-be60-c7dee75c973b', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': '{}', 'origin': '[email protected]', 'reply_to': '257ab156-57fa-3806-bdf1-28d5501b0472', 'correlation_id': 'cf9c0268-3071-418a-be60-c7dee75c973b', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}}, b'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]', 'application/json', 'utf-8') kwargs:{}) 
[2017-05-31 22:50:00,007: DEBUG/MainProcess] Task accepted: bar[cf9c0268-3071-418a-be60-c7dee75c973b] pid:63836 

... 

[2017-05-31 23:00:00,000: INFO/Beat] Scheduler: Sending due task do-bar-every-midnight (bar) 
[2017-05-31 23:00:00,002: DEBUG/Beat] bar sent. id->24c08011-a490-490e-a2fc-fc5ddd12ef27 
[2017-05-31 23:00:00,002: INFO/MainProcess] Received task: bar[24c08011-a490-490e-a2fc-fc5ddd12ef27] 
[2017-05-31 23:00:00,003: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x80740b1e0> (args:('bar', '24c08011-a490-490e-a2fc-fc5ddd12ef27', {'lang': 'py', 'task': 'bar', 'id': '24c08011-a490-490e-a2fc-fc5ddd12ef27', 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': '24c08011-a490-490e-a2fc-fc5ddd12ef27', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': '{}', 'origin': '[email protected]', 'reply_to': '257ab156-57fa-3806-bdf1-28d5501b0472', 'correlation_id': '24c08011-a490-490e-a2fc-fc5ddd12ef27', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}}, b'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]', 'application/json', 'utf-8') kwargs:{}) 
[2017-05-31 23:00:00,004: DEBUG/MainProcess] Task accepted: bar[24c08011-a490-490e-a2fc-fc5ddd12ef27] pid:63838 
... 
[2017-05-31 23:05:37,901: INFO/PoolWorker-4] Task bar[24c08011-a490-490e-a2fc-fc5ddd12ef27] succeeded in 337.8967144470662s: datetime.datetime(2017, 5, 31, 23, 5, 37, 899685) 
... 
[2017-05-31 23:05:40,014: INFO/PoolWorker-2] Task bar[cf9c0268-3071-418a-be60-c7dee75c973b] succeeded in 940.0073816571385s: datetime.datetime(2017, 5, 31, 23, 5, 40, 10523) 

我追蹤到日誌之前數天,任務「欄」

[2017-05-23 05:37:51,155: INFO/Beat] beat: Starting... 
... 
[2017-05-23 22:50:00,004: DEBUG/Beat] bar sent. id->2bfe3ab4-abfd-419e-bfe1-8f64cebe0739 
[2017-05-23 23:00:00,002: DEBUG/Beat] bar sent. id->96eeb154-688a-4e19-b793-c1017e3dcdfc 
[2017-05-24 22:50:00,003: DEBUG/Beat] bar sent. id->b02db272-712f-4a5b-83d7-1823181367fa 
[2017-05-24 23:00:00,002: DEBUG/Beat] bar sent. id->f510be26-7155-4707-b0da-309bf6e4d938 
[2017-05-25 23:00:00,004: DEBUG/Beat] bar sent. id->67108a9f-5629-46e8-bd32-e7c7a5eaaa31 
[2017-05-26 23:00:00,002: DEBUG/Beat] bar sent. id->d85cc8a0-c68d-4762-bd81-8ddfea19f177 
[2017-05-27 23:00:00,002: DEBUG/Beat] bar sent. id->a1203df4-ac84-43ea-8ba8-c6f984e205d1 
[2017-05-28 23:00:00,005: DEBUG/Beat] bar sent. id->716f01dd-f802-44a4-af40-801505317e71 

我猜的情況下,作爲@yetship之前說的,它運行時的兩倍第一推出任務後,跑芹菜拍。但是當芹菜摔打開始時,它並沒有運行確切的時間,它比預定時間提前了10分鐘。我跑過芹菜打了05-23 05:37:51

我覺得問題是指定的,我怎麼能防止它跑10分鐘前..?並讓它運行一次?

回答

0

它沒有任何問題。 的原因是芹菜在05-31運行,當它開始時,我認爲你以前沒有運行它,它發現在05-01它不運行,芹菜認爲它應該運行,所以它運行。

和06-01,這次運行是在六月份,它運行在正確的時間。

所以結果是我認爲你在2017-05-31 23:50:00開始你的芹菜打漿機,不是嗎?

+0

謝謝您的回答! :D,但那時我沒有跑芹菜,實際上我已經在2017-05-19跑了芹菜deamon。那時芹菜從未跑過任務,直到2017-05-31 23:50:00 ...:O 並且我可以提供與您所寫的相關的文檔嗎? :) 謝謝!! –

+0

如果這是真的,有什麼辦法可以阻止芹菜節拍執行過去約會嗎? thx再次! –

+0

這很奇妙,你有沒有改變機器的時間?關於我之前說的,也許你可以在[github](https://github.com/celery/celery/blob/master/celery/schedules.py)查看芹菜crontab的代碼實現@zisoozzoi – Liqiang

0

一個可能發生的原因是因爲你的

芹菜下來,這是應該執行的任務留在隊列中,不能被執行,但在23被執行: 50(當芹菜升起時)。你能否確認芹菜始終處於運轉狀態?

此外,這些任務是否按預期執行?

+0

我看了日誌,但是找不到西芹的日誌:O 我發現從 [2017-05-31 01:33:42,396]〜[2017-06-01 01:54: 00861] –