【发布时间】:2018-03-21 10:04:40
【问题描述】:
我的通知模型中有send_time 字段。届时我想向所有移动客户端发送通知。
我现在正在做的是,我已经创建了一个任务并为每一分钟安排了它
tasks.py
@app.task(name='app.tasks.send_notification')
def send_notification():
# here is logic to filter notification that fall inside that 1 minute time span
cron.push_notification()
settings.py
CELERYBEAT_SCHEDULE = {
'send-notification-every-1-minute': {
'task': 'app.tasks.send_notification',
'schedule': crontab(minute="*/1"),
},
}
一切都按预期工作。
问题:
有没有办法根据send_time字段安排任务,所以我不必每分钟都安排任务。
更具体地说我想创建一个新的任务实例,因为我的通知模型获取新条目并根据该记录的send_time 字段安排它。
注意:我正在使用 celery 与 django 的新集成,而不是 django-celery 包
【问题讨论】:
标签: django celery celerybeat