Skip to content

Commit 7fa355b

Browse files
abhizipstackclaude
andcommitted
fix: address Greptile review — compute next_run_time + memoize STATUS_META
P1: next_run_time was exposed in the API but never written, so the "Next Run" column was always empty. Added _compute_next_run_time that uses celery's remaining_estimate on the PeriodicTask's schedule to derive the next run from the last run time. Falls back to task.next_run_time if it happens to be set directly. P2: STATUS_META was rebuilt on every render inside the component body. Wrapped in useMemo with [token] as the dependency so it only recomputes when the antd theme changes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 16ba183 commit 7fa355b

2 files changed

Lines changed: 64 additions & 39 deletions

File tree

backend/backend/core/scheduler/views.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
logger = logging.getLogger(__name__)
2121

2222

23+
24+
def _compute_next_run_time(periodic, last_run_at):
25+
"""Derive the next run time from a PeriodicTask's schedule."""
26+
if not periodic or not periodic.enabled:
27+
return None
28+
try:
29+
schedule = periodic.schedule
30+
reference = last_run_at or periodic.last_run_at or timezone.now()
31+
remaining = schedule.remaining_estimate(reference)
32+
return reference + remaining
33+
except Exception:
34+
return None
35+
36+
2337
def _is_valid_project_id(project_id):
2438
"""Check if project_id is a real UUID (not a placeholder like '_all' or 'all')."""
2539
try:
@@ -164,7 +178,9 @@ def _serialize_task(task):
164178
"task_status": task.status,
165179
"task_run_time": task.task_run_time,
166180
"task_completion_time": task.task_completion_time,
167-
"next_run_time": task.next_run_time,
181+
"next_run_time": task.next_run_time or _compute_next_run_time(
182+
periodic, task.task_run_time
183+
),
168184
"task_type": task_type,
169185
"description": task.description,
170186
"environment": {

frontend/src/ide/run-history/Runhistory.jsx

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -363,44 +363,53 @@ const Runhistory = () => {
363363
[]
364364
);
365365

366-
const STATUS_META = {
367-
SUCCESS: {
368-
icon: <CheckCircleFilled />,
369-
label: "Succeeded",
370-
color: token.colorSuccess,
371-
bg: token.colorSuccessBg,
372-
},
373-
FAILURE: {
374-
icon: <CloseCircleFilled />,
375-
label: "Failed",
376-
color: token.colorError,
377-
bg: token.colorErrorBg,
378-
},
379-
STARTED: {
380-
icon: <SyncOutlined spin />,
381-
label: "Running",
382-
color: token.colorInfo,
383-
bg: token.colorInfoBg,
384-
},
385-
RETRY: {
386-
icon: <SyncOutlined spin />,
387-
label: "Retrying",
388-
color: token.colorWarning,
389-
bg: token.colorWarningBg,
390-
},
391-
REVOKED: {
392-
icon: <ClockCircleOutlined />,
393-
label: "Revoked",
394-
color: token.colorTextSecondary,
395-
bg: token.colorFillQuaternary,
396-
},
397-
PENDING: {
398-
icon: <ClockCircleOutlined />,
399-
label: "Pending",
400-
color: token.colorTextSecondary,
401-
bg: token.colorFillQuaternary,
402-
},
403-
};
366+
const STATUS_META = useMemo(
367+
() => ({
368+
SUCCESS: {
369+
icon: <CheckCircleFilled />,
370+
label: "Succeeded",
371+
color: token.colorSuccess,
372+
bg: token.colorSuccessBg,
373+
},
374+
FAILURE: {
375+
icon: <CloseCircleFilled />,
376+
label: "Failed",
377+
color: token.colorError,
378+
bg: token.colorErrorBg,
379+
},
380+
STARTED: {
381+
icon: <SyncOutlined spin />,
382+
label: "Running",
383+
color: token.colorInfo,
384+
bg: token.colorInfoBg,
385+
},
386+
RETRY: {
387+
icon: <SyncOutlined spin />,
388+
label: "Retrying",
389+
color: token.colorWarning,
390+
bg: token.colorWarningBg,
391+
},
392+
REVOKED: {
393+
icon: <ClockCircleOutlined />,
394+
label: "Revoked",
395+
color: token.colorTextSecondary,
396+
bg: token.colorFillQuaternary,
397+
},
398+
PENDING: {
399+
icon: <ClockCircleOutlined />,
400+
label: "Pending",
401+
color: token.colorTextSecondary,
402+
bg: token.colorFillQuaternary,
403+
},
404+
RUNNING: {
405+
icon: <SyncOutlined spin />,
406+
label: "Running",
407+
color: token.colorInfo,
408+
bg: token.colorInfoBg,
409+
},
410+
}),
411+
[token]
412+
);
404413

405414
/* ─── empty text ─── */
406415
const emptyDescription = useMemo(() => {

0 commit comments

Comments
 (0)