4
我想安排一項任務在將來的不同時間運行。我在調用任務時嘗試使用eta選項來執行此操作。這部分工作正常,但同時,我想對任務進行限制。我無法做到這一點:安排任務在未來運行,同時也讓芹菜尊重費率限制。當通過'eta'選項安排時不考慮Celery rate_limit
下面是一個例子(rate_limit_eta.py)
from celery import Celery
from datetime import datetime, timedelta
app = Celery('rate_limit_eta', broker='amqp://[email protected]//')
@app.task(rate_limit='4/m')
def my_task():
print 'execution timestamp: {}'.format(datetime.utcnow())
if __name__ == '__main__':
now = datetime.utcnow()
d = now + timedelta(seconds=5)
print now
for i in range(10):
my_task.apply_async(eta=d)
在該循環中,當我稱之爲 'my_task' 與ETA = d,任務得到儘可能快地執行。 rate_limit不受尊重。
my_task.apply_async(eta=d)
[2015-06-12 13:45:15,750: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.748498
[2015-06-12 13:45:15,757: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.757757
[2015-06-12 13:45:15,760: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.759992
[2015-06-12 13:45:15,763: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.763614
[2015-06-12 13:45:15,766: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.765996
[2015-06-12 13:45:15,768: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.768424
[2015-06-12 13:45:15,771: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.771079
[2015-06-12 13:45:15,774: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.774561
[2015-06-12 13:45:15,777: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.777425
[2015-06-12 13:45:15,780: WARNING/Worker-1] execution timestamp: 2015-06-12 13:45:15.780207
但是,如果我沒有安排任務(即沒有eta),那麼速率限制是強制執行的。
my_task.apply_async()
[2015-06-12 13:47:05,844: WARNING/Worker-1] execution timestamp: 2015-06-12 13:47:05.843872
[2015-06-12 13:47:05,850: WARNING/Worker-1] execution timestamp: 2015-06-12 13:47:05.850502
[2015-06-12 13:47:21,919: WARNING/Worker-1] execution timestamp: 2015-06-12 13:47:21.919120
[2015-06-12 13:47:35,937: WARNING/Worker-1] execution timestamp: 2015-06-12 13:47:35.937060
[2015-06-12 13:47:51,959: WARNING/Worker-1] execution timestamp: 2015-06-12 13:47:51.959174
[2015-06-12 13:48:05,976: WARNING/Worker-1] execution timestamp: 2015-06-12 13:48:05.976197
[2015-06-12 13:48:21,998: WARNING/Worker-1] execution timestamp: 2015-06-12 13:48:21.998254
[2015-06-12 13:48:36,014: WARNING/Worker-1] execution timestamp: 2015-06-12 13:48:36.014837
[2015-06-12 13:48:52,041: WARNING/Worker-1] execution timestamp: 2015-06-12 13:48:52.041326
[2015-06-12 13:49:06,057: WARNING/Worker-1] execution timestamp: 2015-06-12 13:49:06.057286
我做錯了什麼?
任何人有任何想法呢? – apatel
是誰在這方面有想法?我可以使用幫助。謝謝。 – apatel