feat: add cron job trigger for background jobs

Extends the job to support both event-based and cron-scheduled triggers
This commit is contained in:
Ephraim Atta-Duncan
2024-11-20 15:00:45 +00:00
parent 2e2bc8382f
commit 8b771d36d2
10 changed files with 94 additions and 35 deletions

View File

@ -26,16 +26,26 @@ export type TriggerJobOptions<Definitions extends ReadonlyArray<JobDefinition> =
};
}[number];
export type CronTrigger = {
type: 'cron';
schedule: string;
name?: string;
};
export type EventTrigger<N extends string = string> = {
type: 'event';
name: N;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type JobDefinition<Name extends string = string, Schema = any> = {
id: string;
name: string;
version: string;
enabled?: boolean;
trigger: {
name: Name;
schema?: z.ZodType<Schema>;
};
trigger:
| (EventTrigger<Name> & { schema?: z.ZodType<Schema> })
| (CronTrigger & { schema?: z.ZodType<Schema> });
handler: (options: { payload: Schema; io: JobRunIO }) => Promise<Json | void>;
};