【发布时间】:2023-11-14 01:47:01
【问题描述】:
我想验证设置 celery 任务的时间限制是否有效。
我目前的配置如下所示:
CELERYD_TASK_SOFT_TIME_LIMIT = 30
CELERYD_TASK_TIME_LIMIT = 120
task_soft_time_limit = 29
task_time_limit = 44_LIMIT = 120
我正在重载超时参数,因为似乎有name change coming,我只是想确保我至少达到了一次超时。
但是当我在调试器中运行测试时,cellery app.conf 字典看起来像这样:
(Pdb) app.conf['task_time_limit'] == None
True
(Pdb) app.conf['task_soft_time_limit'] == None
True
(Pdb) app.conf['CELERYD_TASK_SOFT_TIME_LIMIT']
30
(Pdb) app.conf['CELERYD_TASK_TIME_LIMIT']
120
我编写了一个测试,我相信它会触发超时,但从未引发任何错误:
@app.task(soft_time_limit=15)
def time_out_task():
import time
count = 0
#import pdb; pdb.set_trace()
while count < 1000:
time.sleep(1)
count += 1
print(count)
我的问题如下:
- 我应该为软时间限制和硬时间限制设置哪些锥形设置?
- 如何在测试中执行向我证明时间限制到位的任务。
谢谢
【问题讨论】:
标签: python redis celery django-celery