Skip to content

Commit 734be4a

Browse files
sshaderConvex, Inc.
authored and
Convex, Inc.
committed
Make nextRun in crons system UDF required (#36390)
GitOrigin-RevId: bd9ab9997aa2020e6d13b252d17aa15fbf99aec1
1 parent e72e377 commit 734be4a

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

npm-packages/dashboard-common/src/features/schedules/components/crons/CronJobsContent.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function Details({
100100
delete router.query.id;
101101
void router.push({ query: router.query });
102102
};
103-
const currentlyRunning = cronJob.nextRun?.state.type === "inProgress";
103+
const currentlyRunning = cronJob.nextRun.state.type === "inProgress";
104104

105105
return (
106106
<div className="flex h-full w-full max-w-6xl flex-col gap-4">
@@ -201,11 +201,9 @@ export function TopCronJobLogListItem({
201201
const url = useFunctionUrl(cronJob.cronSpec.udfPath);
202202

203203
const { nextRun } = cronJob;
204-
const nextTs = nextRun?.nextTs;
205-
const timestamp = nextTs
206-
? formatDateTime(new Date(Number(nextTs / BigInt(1000000))))
207-
: null;
208-
const currentlyRunning = nextRun?.state.type === "inProgress";
204+
const { nextTs, state } = nextRun;
205+
const timestamp = formatDateTime(new Date(Number(nextTs / BigInt(1000000))));
206+
const currentlyRunning = state.type === "inProgress";
209207

210208
// Make a quickly-updating timer to make function execution feel fast.
211209
// To avoid a React render every frame (often fine but can gum things up),

npm-packages/dashboard-common/src/features/schedules/components/crons/CronsTable.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ function PrevNextTs({
136136
nextDate: Date | undefined;
137137
prevDate: Date;
138138
prevRun: CronJobLog | undefined;
139-
nextRun: Doc<"_cron_next_run"> | undefined;
139+
nextRun: Doc<"_cron_next_run">;
140140
}
141141
>) {
142-
const isRunning = value.nextRun?.state.type === "inProgress";
142+
const isRunning = value.nextRun.state.type === "inProgress";
143143
return (
144144
<div className="flex flex-col truncate">
145145
<PrevTs date={value.prevDate} isRunning={isRunning} run={value.prevRun} />
@@ -208,9 +208,7 @@ function Args({ value }: CellProps<CronDatum, JSONValue[]>) {
208208

209209
function cronDatum(cronJob: CronJobWithRuns) {
210210
const { name, cronSpec, lastRun, nextRun } = cronJob;
211-
const nextDate = nextRun
212-
? new Date(Number(nextRun.nextTs / BigInt("1000000")))
213-
: undefined;
211+
const nextDate = new Date(Number(nextRun.nextTs / BigInt("1000000")));
214212
const prevDate = lastRun && new Date(Number(lastRun.ts / BigInt("1000000")));
215213
return {
216214
name,
@@ -219,7 +217,7 @@ function cronDatum(cronJob: CronJobWithRuns) {
219217
prevDate,
220218
nextDate,
221219
prevRun: lastRun,
222-
state: nextRun?.state,
220+
state: nextRun.state,
223221
},
224222
udfPath: cronSpec.udfPath,
225223
udfArgs:

npm-packages/system-udfs/convex/_system/frontend/common.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ export type CronSpec = Doc<"_cron_jobs">["cronSpec"];
9797
export type CronSchedule = Doc<"_cron_jobs">["cronSpec"]["cronSchedule"];
9898
export type CronJobLog = Doc<"_cron_job_logs">;
9999
export type CronJobWithRuns = Doc<"_cron_jobs"> & {
100-
// only undefined while feature-flagged (but still might be null)
101-
lastRun: CronJobLog | null | undefined;
102-
nextRun: Doc<"_cron_next_run"> | null | undefined;
100+
lastRun: CronJobLog | null;
101+
nextRun: Doc<"_cron_next_run">;
103102
};
104103

105104
export type Modules = Map<string, Module>;

npm-packages/system-udfs/convex/_system/frontend/listCronJobs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export default queryPrivateSystem({
1717
.query("_cron_next_run")
1818
.withIndex("by_cron_job_id", (q) => q.eq("cronJobId", job._id))
1919
.first();
20+
if (nextRun === null) {
21+
throw new Error("No next run found for cron job");
22+
}
2023
jobsWithRuns.push({
2124
...job,
2225
lastRun: lastRun,

0 commit comments

Comments
 (0)