[英]Can't get Celery run_every property to work
I'm trying to create some Celery Periodic Tasks, and a few of them need to have the ability to change the run_every time at runtime. 我正在尝试创建一些Celery定期任务,其中一些需要能够在运行时更改run_every时间。 The Celery documentation says I should be able to do this by turning the run_every attribute into a property ( http://packages.python.org/celery/faq.html#can-i-change-the-interval-of-a-periodic-task-at-runtime ). Celery文档说我应该可以通过将run_every属性变成一个属性来做到这一点( http://packages.python.org/celery/faq.html#can-i-change-the-interval-of-a-运行时定期任务 )。
Here is what I'm doing: 这是我在做什么:
class ParseSomeStuffTask(PeriodicTask):
def run(self, **kwargs):
# Do stuff
@property
def run_every(self):
if datetime.now().weekday() in [1, 2, 3]:
return timedelta(minutes=15)
else:
return timedelta(seconds=40)
Unfortunately, when I turn on celerybeat, I get the following error: 不幸的是,当我打开celerybeat时,出现以下错误:
[Thu Sep 09 15:44:40 2010: CRITICAL/828]: celerybeat raised exception : 'datetime.timedelta' object has no attribute 'is_due' [2010年9月9日15:44:40:CRITICAL / 828]:celerybeat引发了异常:'datetime.timedelta'对象没有属性'is_due'
It then shuts down. 然后关闭。 The Celery documentation doesn't really go into what to return when making run_every a property, and I haven't had any luck searching Google. Celery文档并没有真正考虑将run_every设置为属性时返回什么,而且我在搜索Google方面没有任何运气。 Celery changelogs say its been able to change a Periodic Task's interval at runtime since version 1.0.0. Celery changelogs表示,自1.0.0版以来,它能够在运行时更改定期任务的间隔。
Dev. 开发人员 Environment: 环境:
Celery 2.0 supports different schedule behaviors. Celery 2.0支持不同的计划行为。 There's celery.task.schedules.schedule
and celery.task.schedules.crontab
. 有celery.task.schedules.schedule
和celery.task.schedules.crontab
。
You have to return one of these, or make your own subclass of schedule. 您必须返回其中之一,或者自己创建时间表的子类。
from celery.task.schedules import schedule
@property
def run_every(self):
if datetime.now().weekday() in [1, 2, 3]:
return schedule(timedelta(minutes=15))
else:
return schedule(timedelta(seconds=40))
The run_every
attribute will be automatically converted at instantiation, but not later. run_every
属性将在实例化时自动转换,但不会稍后转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.