简体   繁体   中英

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

The old docs for version 2.4 say there is a class PeriodicClassMeta which has the metadata for the task, including last_run . However the docs for django-celery don't include any usage information for the models or how to set up 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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