无法让 Celery run_every 属性正常工作
我正在尝试创建一些 Celery 定期任务,其中一些需要能够在运行时更改 run_every 。 Celery 文档说我应该能够通过将 run_every 属性转换为属性来做到这一点(http://packages.python.org/celery/faq.html#can-i-change-the-interval-of-a-运行时周期性任务)。
这是我正在做的事情:
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)
不幸的是,当我打开 celerybeat 时,出现以下错误:
[2010 年 9 月 9 日星期四 15:44:40: CRITICAL/828]:celerybeat 升高 例外 : 'datetime.timedelta' 对象没有 属性“is_due”
然后关闭。 Celery 文档并没有真正讨论将 run_every 设置为属性时要返回什么,而且我在 Google 上搜索也没有运气。 Celery 变更日志称,自版本 1.0.0 以来,它能够在运行时更改定期任务的间隔。
开发。环境:
- Python 2.6.5
- Django 1.2.1
- Celery 2.0.2
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. 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).
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:
[Thu Sep 09 15:44:40 2010:
CRITICAL/828]: celerybeat raised
exception :
'datetime.timedelta' object has no
attribute '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 changelogs say its been able to change a Periodic Task's interval at runtime since version 1.0.0.
Dev. Environment:
- Python 2.6.5
- Django 1.2.1
- Celery 2.0.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Celery 2.0 支持不同的调度行为。有 celery.task.schedules.schedule 和 celery.task.schedules.crontab 。
您必须返回其中之一,或者创建您自己的时间表子类。
run_every
属性将在实例化时自动转换,但不晚了。
Celery 2.0 supports different schedule behaviors. There's
celery.task.schedules.schedule
andcelery.task.schedules.crontab
.You have to return one of these, or make your own subclass of schedule.
The
run_every
attribute will be automatically converted at instantiation,but not later.