Skip to content

Commit 1a116b7

Browse files
fix: compute next_run_time from current time instead of stale last_run_at
remaining_estimate(last_run_at) returns a negative duration when last_run_at is old, producing a past timestamp and hiding the countdown tag in the Jobs List UI.
1 parent 6da27ed commit 1a116b7

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

backend/backend/core/scheduler/views.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323

2424

2525

26-
def _compute_next_run_time(periodic, last_run_at):
26+
def _compute_next_run_time(periodic):
2727
"""Derive the next run time from a PeriodicTask's schedule."""
2828
if not periodic or not periodic.enabled:
2929
return None
3030
try:
3131
schedule = periodic.schedule
32-
reference = last_run_at or periodic.last_run_at or timezone.now()
33-
remaining = schedule.remaining_estimate(reference)
34-
return timezone.now() + remaining
32+
now = timezone.now()
33+
remaining = schedule.remaining_estimate(now)
34+
return now + remaining
3535
except Exception:
36-
logger.debug("Failed to compute next_run_time for %s", periodic, exc_info=True)
36+
logger.warning("Failed to compute next_run_time for %s", periodic, exc_info=True)
3737
return None
3838

3939

@@ -181,9 +181,7 @@ def _serialize_task(task):
181181
"task_status": task.status,
182182
"task_run_time": task.task_run_time,
183183
"task_completion_time": task.task_completion_time,
184-
"next_run_time": task.next_run_time or _compute_next_run_time(
185-
periodic, task.task_run_time
186-
),
184+
"next_run_time": _compute_next_run_time(periodic) or task.next_run_time,
187185
"task_type": task_type,
188186
"description": task.description,
189187
"environment": {

0 commit comments

Comments
 (0)