refactor(cron): share execution id helper

This commit is contained in:
Ayaan Zaidi
2026-04-19 21:00:52 +05:30
parent 055c17b088
commit f44a7423c2
3 changed files with 7 additions and 10 deletions

3
src/cron/run-id.ts Normal file
View File

@@ -0,0 +1,3 @@
export function createCronExecutionId(jobId: string, startedAt: number): string {
return `cron:${jobId}:${startedAt}`;
}

View File

@@ -6,6 +6,7 @@ import {
createRunningTaskRun,
failTaskRunByRunId,
} from "../../tasks/detached-task-runtime.js";
import { createCronExecutionId } from "../run-id.js";
import type { CronJob, CronJobCreate, CronJobPatch } from "../types.js";
import {
applyJobPatch,
@@ -394,10 +395,6 @@ type ManualRunPreflightResult =
let nextManualRunId = 1;
function createCronTaskRunId(jobId: string, startedAt: number): string {
return `cron:${jobId}:${startedAt}`;
}
async function skipInvalidPersistedManualRun(params: {
state: CronServiceState;
job: CronJob;
@@ -445,7 +442,7 @@ function tryCreateManualTaskRun(params: {
job: CronJob;
startedAt: number;
}): string | undefined {
const runId = createCronTaskRunId(params.job.id, params.startedAt);
const runId = createCronExecutionId(params.job.id, params.startedAt);
try {
createRunningTaskRun({
runtime: "cron",

View File

@@ -10,6 +10,7 @@ import {
} from "../../tasks/detached-task-runtime.js";
import { clearCronJobActive, markCronJobActive } from "../active-jobs.js";
import { resolveCronDeliveryPlan } from "../delivery-plan.js";
import { createCronExecutionId } from "../run-id.js";
import { sweepCronRunSessions } from "../session-reaper.js";
import type {
CronDeliveryStatus,
@@ -130,16 +131,12 @@ export function normalizeCronRunErrorText(err: unknown): string {
return String(err);
}
function createCronTaskRunId(jobId: string, startedAt: number): string {
return `cron:${jobId}:${startedAt}`;
}
function tryCreateCronTaskRun(params: {
state: CronServiceState;
job: CronJob;
startedAt: number;
}): string | undefined {
const runId = createCronTaskRunId(params.job.id, params.startedAt);
const runId = createCronExecutionId(params.job.id, params.startedAt);
try {
createRunningTaskRun({
runtime: "cron",