Browse Source

feat: add scheduler Drizzle schema (scheduled_tasks, task_execution_logs)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
main
npmrun 2 weeks ago
parent
commit
a079ec159a
  1. 42
      packages/drizzle-pkg/lib/schema/scheduler.ts

42
packages/drizzle-pkg/lib/schema/scheduler.ts

@ -0,0 +1,42 @@
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
export const scheduledTasks = sqliteTable("scheduled_tasks", {
id: text("id").primaryKey(),
name: text("name").notNull(),
cronExpression: text("cron_expression").notNull(),
type: text("type").notNull(), // "function" | "http"
// function type fields
functionName: text("function_name"),
functionPayload: text("function_payload"),
// http type fields
httpMethod: text("http_method"),
httpUrl: text("http_url"),
httpHeaders: text("http_headers"),
httpBody: text("http_body"),
catchUp: integer("catch_up").default(0).notNull(),
enabled: integer("enabled").default(1).notNull(),
maxRetries: integer("max_retries").default(0).notNull(),
retryDelaySeconds: integer("retry_delay_seconds").default(60).notNull(),
timeoutSeconds: integer("timeout_seconds").default(300).notNull(),
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
});
export const taskExecutionLogs = sqliteTable("task_execution_logs", {
id: text("id").primaryKey(),
taskId: text("task_id")
.notNull()
.references(() => scheduledTasks.id),
status: text("status").notNull(), // "running" | "success" | "failed"
startedAt: integer("started_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
finishedAt: integer("finished_at", { mode: "timestamp_ms" }),
errorMessage: text("error_message"),
resultSummary: text("result_summary"),
});
Loading…
Cancel
Save