简体   繁体   English

Django计划和排队非定期任务

[英]Django Schedule and queue Non periodic Tasks

I am looking for Job Task Scheduler in Django. 我正在寻找Django中的Job Task Scheduler。 I have looked into django-celery, but all the documentation shows is the periodic scheduling of task. 我研究了django-celery,但是所有文档显示的都是任务的定期调度。 But what I am looking for is to add a task to queue and schedule it at a specific time, till that time the task can go to sleep. 但是我正在寻找的是添加一个任务以在特定时间排队并安排它,直到该任务可以进入睡眠状态。 Also, it has to be executed only once. 同样,它只需要执行一次。 Is my conclusion about django-celery correct? 我对django-celery的结论正确吗? Is there a better way or any other way to schedule non-periodic tasks. 有没有更好的方法或其他任何方式来安排非定期任务。

yes, celery is a good tool for the task, the documentation states exactly what you need, specifically just specify an eta when apply_async a task: 是的,celery是完成任务的好工具, 文档准确说明了您的需求,特别是在apply_async任务时仅指定一个eta:

from celery import task
from datetime import datetime, timedelta

@task()
def add(x, y):
    return x + y

tomorrow = datetime.now() + timedelta(days=1)
add.apply_async(args=[10, 10], eta=tomorrow)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM