-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule-run-task.ts
More file actions
51 lines (46 loc) · 1.91 KB
/
schedule-run-task.ts
File metadata and controls
51 lines (46 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { z } from "zod/v4";
import { createInsertSchema, createSelectSchema, createUpdateSchema } from "./common";
import { scheduleRun } from "./schedule-run";
export const ScheduleRunTaskStatus = z.enum([
"pending",
"running",
"completed",
"failed",
"cancelled",
]);
export type ScheduleRunTaskStatus = z.infer<typeof ScheduleRunTaskStatus>;
export const scheduleRunTask = sqliteTable(
"schedule_run_task",
{
id: text("id").primaryKey(),
scheduleRunId: text("schedule_run_id")
.notNull()
.references(() => scheduleRun.id, { onDelete: "cascade" }),
status: text("status").notNull().$type<ScheduleRunTaskStatus>().default("pending"),
results: text("results", { mode: "json" }).$type<Record<string, unknown> | null>(),
attempts: integer("attempts").notNull().default(0),
maxAttempts: integer("max_attempts").notNull().default(3),
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }),
},
(t) => [
index("schedule_run_task_schedule_run_id").on(t.scheduleRunId),
index("schedule_run_task_status").on(t.status),
],
);
export const ScheduleRunTask = createSelectSchema(scheduleRunTask, {
status: ScheduleRunTaskStatus,
results: z.record(z.string(), z.unknown()).nullable(),
});
export type ScheduleRunTask = z.output<typeof ScheduleRunTask>;
export const ScheduleRunTaskInsert = createInsertSchema(scheduleRunTask, {
status: ScheduleRunTaskStatus,
results: z.record(z.string(), z.unknown()).nullable(),
});
export type ScheduleRunTaskInsert = z.output<typeof ScheduleRunTaskInsert>;
export const ScheduleRunTaskUpdate = createUpdateSchema(scheduleRunTask, {
status: ScheduleRunTaskStatus,
results: z.record(z.string(), z.unknown()).nullable(),
});
export type ScheduleRunTaskUpdate = z.output<typeof ScheduleRunTaskUpdate>;