Skip to content

Commit ad1faaa

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 dbdf7b5 commit ad1faaa

2 files changed

Lines changed: 58 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: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -312,44 +312,47 @@ const Runhistory = () => {
312312
return { scope, models };
313313
};
314314

315-
const STATUS_META = {
316-
SUCCESS: {
317-
icon: <CheckCircleFilled />,
318-
label: "Succeeded",
319-
color: token.colorSuccess,
320-
bg: token.colorSuccessBg,
321-
},
322-
FAILURE: {
323-
icon: <CloseCircleFilled />,
324-
label: "Failed",
325-
color: token.colorError,
326-
bg: token.colorErrorBg,
327-
},
328-
STARTED: {
329-
icon: <SyncOutlined spin />,
330-
label: "Running",
331-
color: token.colorInfo,
332-
bg: token.colorInfoBg,
333-
},
334-
RETRY: {
335-
icon: <SyncOutlined spin />,
336-
label: "Retrying",
337-
color: token.colorWarning,
338-
bg: token.colorWarningBg,
339-
},
340-
REVOKED: {
341-
icon: <ClockCircleOutlined />,
342-
label: "Revoked",
343-
color: token.colorTextSecondary,
344-
bg: token.colorFillQuaternary,
345-
},
346-
PENDING: {
347-
icon: <ClockCircleOutlined />,
348-
label: "Pending",
349-
color: token.colorTextSecondary,
350-
bg: token.colorFillQuaternary,
351-
},
352-
};
315+
const STATUS_META = useMemo(
316+
() => ({
317+
SUCCESS: {
318+
icon: <CheckCircleFilled />,
319+
label: "Succeeded",
320+
color: token.colorSuccess,
321+
bg: token.colorSuccessBg,
322+
},
323+
FAILURE: {
324+
icon: <CloseCircleFilled />,
325+
label: "Failed",
326+
color: token.colorError,
327+
bg: token.colorErrorBg,
328+
},
329+
STARTED: {
330+
icon: <SyncOutlined spin />,
331+
label: "Running",
332+
color: token.colorInfo,
333+
bg: token.colorInfoBg,
334+
},
335+
RETRY: {
336+
icon: <SyncOutlined spin />,
337+
label: "Retrying",
338+
color: token.colorWarning,
339+
bg: token.colorWarningBg,
340+
},
341+
REVOKED: {
342+
icon: <ClockCircleOutlined />,
343+
label: "Revoked",
344+
color: token.colorTextSecondary,
345+
bg: token.colorFillQuaternary,
346+
},
347+
PENDING: {
348+
icon: <ClockCircleOutlined />,
349+
label: "Pending",
350+
color: token.colorTextSecondary,
351+
bg: token.colorFillQuaternary,
352+
},
353+
}),
354+
[token]
355+
);
353356

354357
/* ─── empty text ─── */
355358
const emptyDescription = useMemo(() => {

0 commit comments

Comments
 (0)