简体   繁体   English

Celery计划的任务以及每个任务实例的到期时间?

[英]Celery scheduled tasks with expiration time for each task instance?

I have a django app with celery 4.1.0 and celery beat with database scheduler. 我有一个celery 4.1.0和celery beat与数据库调度程序的django应用程序。 What I want is to run periodic tasks from admin site and set expiration time for each of this tasks. 我想要的是从管理站点运行定期任务,并为每个任务设置到期时间。 expire property in PeriodicTask is a time scheduler stops creating new messages for that task but i want the expiration to revoke tasks which are scheduled but are older than some value eg one hour. PeriodicTask中的expire属性是一个时间计划程序,该时间计划程序停止为该任务创建新消息,但我希望该过期时间撤消已计划但早于某个值的任务,例如一个小时。 how to do this? 这个怎么做?

I am really confused with celery documentation and differences between different versions of it. 我对芹菜文档及其不同版本之间的差异感到非常困惑。

听起来您需要使用自定义调度程序类

I solved it by running an scheduled task which runs defined task with desired expiry time: 我通过运行计划的任务解决了该问题,该任务以所需的到期时间运行定义的任务:

@shared_task(bind=True, queue='q1', max_retries=3)
def parent_task(self, arg1):
    child_task.apply_async(kwargs={'arg1': arg1}, expires=86400)


@shared_task(bind=True, queue='q1', max_retries=3)
def child_task(self, arg1):
    pass

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

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