简体   繁体   English

django-celery PeriodicTask使用DatabaseScheduler获取上次运行时间

[英]django-celery PeriodicTask getting last run time using DatabaseScheduler

using django-celery, with the backend djcelery.schedulers.DatabaseScheduler , I need to access the last run time for a celery.task.PeriodicTask 使用Django,芹菜,与后端djcelery.schedulers.DatabaseScheduler ,我需要访问的最后运行时间为celery.task.PeriodicTask

The old docs for version 2.4 say there is a class PeriodicClassMeta which has the metadata for the task, including last_run . 版本2.4的旧文档说有一个类PeriodicClassMeta ,它包含任务的元数据,包括last_run However the docs for django-celery don't include any usage information for the models or how to set up PeriodicTasks . 但是, django-celery的文档不包含模型的任何使用信息或如何设置PeriodicTasks

So, my question is, how do you setup PeriodicTasks in django-celery, using the DatabaseScheduler backend and access the metadata related to the last run? 所以,我的问题是,如何在django-celery中设置PeriodicTasks ,使用DatabaseScheduler后端并访问与上次运行相关的元数据?

Assuming this task is only run as a periodic task and that task runtimes are shorter than the spacing of the periodic tasks. 假设此任务仅作为周期性任务运行,并且任务运行时间短于周期性任务的间隔。

from djcelery.models import PeriodicTask, TaskMeta

last_run = PeriodicTask.objects.only('last_run_at')\
                               .get(task=task_name).last_run_at
task_meta = TaskMeta.objects.filter(task_id=task_name, date_done__gte=last_run)\
                            .order_by('date_done').only('meta')[:1][0].meta

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

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