Skip to content

Commit

Permalink
fix: 🐛 last_run_at value when PeriodicTask.last_run_at is None
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoQi99 committed Jun 21, 2024
1 parent 5e00d13 commit 5da4f74
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions django_celery_beat_endpoint/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ def get_periodic_tasks(self):
is_due, next_time_to_check = entry.is_due()

tz = entry.schedule.tz
now = timezone.now().astimezone(tz)
last_run_at = entry.last_run_at.astimezone(tz)
next_execution = (
timezone.now() + datetime.timedelta(seconds=next_time_to_check)
).astimezone(tz)

if now.replace(microsecond=0) == last_run_at.replace(microsecond=0):
last_run_at = None
else:
last_run_at = last_run_at.strftime("%Y-%m-%d %H:%M:%S")

next_execution = now + datetime.timedelta(seconds=next_time_to_check)

tasks.append(
{
Expand All @@ -75,7 +80,7 @@ def get_periodic_tasks(self):
[json.dumps(arg, ensure_ascii=False) for arg in entry.args]
)
),
"last_run_at": last_run_at.strftime("%Y-%m-%d %H:%M:%S"),
"last_run_at": last_run_at,
"schedule": str(entry.schedule),
"kwargs": json.dumps(entry.kwargs, ensure_ascii=False),
"is_due": is_due,
Expand Down

0 comments on commit 5da4f74

Please sign in to comment.