DEV Community

Django Celery Beat: How to get the last time a PeriodicTask was run

Pavel Vergeev on February 13, 2020

The problem Suppose you have the following task: import time from django_project.celery import app # set up according to https://do...
Collapse
 
furtivusmaj profile image
Ahmed Mej

My application has 2 periodic tasks which run for a couple of seconds, and run once per day.
Do you recommend using this method ? It's the most natural thing that comes to mind

Collapse
 
vergeev profile image
Pavel Vergeev

Yeah! Especially if you don't really need to scale this solution to thousands different tasks that launch millions of times.

Since writing this article I've moved on to a different project with a big load of users. And you know what? It uses the same solution! Except on this project we store last_run in Redis, not Postgres, since we don't need to persist it forever.

Collapse
 
furtivusmaj profile image
Ahmed Mej

sorry for the late reply and thank you so much for your reply. I guess I will adopt this strategy for my task. Right now it is just the one!
happy new year ^^

Collapse
 
jheld profile image
Jason Held

Curious what is the scale of your tasks? Django celery beat was not necessarily built to handle load, though if you have separated this database to only be used for beat, that may help.

Collapse
 
vergeev profile image
Pavel Vergeev • Edited

My tasks are network-intensive, and are supposed to run for a month or so.

A separate database is a great idea for this kind of tasks, thanks!