feat: scheduled tasks (automations) (#3638)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
7791d6b2bf
commit
335708df8b
24 files changed
+2771
-44
No files matched your search
@@ -52,6 +52,7 @@ import Migration0036 from "./Migrations/036_OrchestrationV2ProviderSessionBindin
|
||||
import Migration0037 from "./Migrations/037_OrchestrationV2ThreadLaunchWorkflows.ts";
|
||||
import Migration0038 from "./Migrations/038_ApplicationEventSource.ts";
|
||||
import Migration0039 from "./Migrations/039_OrchestrationV2EffectCancellation.ts";
|
||||
import Migration0040 from "./Migrations/040_ScheduledTasks.ts";
|
||||
|
||||
/**
|
||||
* Migration loader with all migrations defined inline.
|
||||
@@ -103,6 +104,7 @@ export const migrationEntries = [
|
||||
[37, "OrchestrationV2ThreadLaunchWorkflows", Migration0037],
|
||||
[38, "ApplicationEventSource", Migration0038],
|
||||
[39, "OrchestrationV2EffectCancellation", Migration0039],
|
||||
[40, "ScheduledTasks", Migration0040],
|
||||
] as const;
|
||||
|
||||
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`
|
||||
CREATE TABLE IF NOT EXISTS scheduled_tasks (
|
||||
task_id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
prompt TEXT NOT NULL,
|
||||
enabled INTEGER NOT NULL,
|
||||
schedule_json TEXT NOT NULL,
|
||||
project_id TEXT NOT NULL,
|
||||
thread_id TEXT,
|
||||
workspace_strategy_json TEXT NOT NULL,
|
||||
model_selection_json TEXT NOT NULL,
|
||||
runtime_mode TEXT NOT NULL,
|
||||
interaction_mode TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL,
|
||||
creation_source TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
next_run_at TEXT,
|
||||
last_run_at TEXT,
|
||||
last_run_status TEXT NOT NULL,
|
||||
last_run_error TEXT,
|
||||
run_count INTEGER NOT NULL
|
||||
)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_scheduled_tasks_due
|
||||
ON scheduled_tasks(enabled, next_run_at)
|
||||
WHERE enabled = 1 AND next_run_at IS NOT NULL
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_scheduled_tasks_project
|
||||
ON scheduled_tasks(project_id, updated_at)
|
||||
`;
|
||||
});
|
||||
Reference in new issue
Block a user