@keystrokehq/scheduler 0.0.0-staging-20260714211819
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +126 -0
- package/dist/contract-C5JvbyQ-.cjs +31 -0
- package/dist/contract-C5JvbyQ-.cjs.map +1 -0
- package/dist/contract-E1QJBH6_.mjs +14 -0
- package/dist/contract-E1QJBH6_.mjs.map +1 -0
- package/dist/contract-GpxHe4g6.d.cts +144 -0
- package/dist/contract-GpxHe4g6.d.cts.map +1 -0
- package/dist/contract-GpxHe4g6.d.mts +144 -0
- package/dist/contract-GpxHe4g6.d.mts.map +1 -0
- package/dist/contract.cjs +5 -0
- package/dist/contract.d.cts +2 -0
- package/dist/contract.d.mts +2 -0
- package/dist/contract.mjs +2 -0
- package/dist/index.cjs +768 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +113 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +739 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Sprint Labs, Inc. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This private canonical monorepo contains materials under different terms:
|
|
4
|
+
|
|
5
|
+
- The downstream public projection described by `oss/` is made available under
|
|
6
|
+
the Elastic License 2.0 in `oss/LICENSE`.
|
|
7
|
+
- Code and materials in paths containing an exact `cloud` segment are
|
|
8
|
+
proprietary and governed by the nearest applicable proprietary license.
|
|
9
|
+
|
|
10
|
+
Access to this private repository does not itself grant a license to use, copy,
|
|
11
|
+
modify, distribute, make available, or create derivative works from its
|
|
12
|
+
contents. Sprint Labs employees, contractors, customers, and partners receive
|
|
13
|
+
rights only under their applicable written agreements.
|
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @keystrokehq/scheduler
|
|
2
|
+
|
|
3
|
+
**Layer:** `platform`
|
|
4
|
+
|
|
5
|
+
Job queue and cron/poll schedule sync for [keystroke](../../README.md). Enqueues workflow, agent, and trigger work; ticks due schedules into the queue. No HTTP, no attachment execution, no trigger source definitions.
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
- **`createScheduler`** — queue backend from `SchedulerPlugin` (default: pg-boss on Postgres, Drizzle job table on SQLite), then expose `enqueue`, `startWorker`, `syncTriggerSchedules`, `startScheduleTicker`, and `fireDueSchedules`.
|
|
10
|
+
- **`SchedulerPlugin`** — swap the default scheduler for a custom queue backend.
|
|
11
|
+
- **`createMemoryJobQueue`** — in-process queue for tests (optional `sync: true` drain).
|
|
12
|
+
- **Job types** — `JobQueue`, `Scheduler`, `JobHandler`, `EnqueueInput`, `JobTrigger`, `StopFn` for server handlers and enqueue helpers.
|
|
13
|
+
- **Schedule sync** — `syncTriggerSchedules` (on `Scheduler`) upserts rows in `trigger_schedules` via `@keystrokehq/database`, resolving cron strings with **`resolveCronSchedule`** and next run times with **`nextTriggerRunAt`** from `@keystrokehq/trigger`.
|
|
14
|
+
- **Trigger firing** — pluggable `TriggerScheduler`. pg-boss (Postgres) and BullMQ register native cron schedules on `sync`, so there is no per-second poll; the SQLite/self-host DB queue uses the **schedule ticker** (background loop claims due schedules and enqueues `kind: "trigger"` jobs). `trigger_schedules` stays the source of truth, reconciled into the firing backend on every `sync`.
|
|
15
|
+
|
|
16
|
+
Queue implementations (`database-queue`, `pg-boss-queue`) and standalone `syncTriggerSchedules` / `resolveTriggerSchedule` stay internal unless a consumer needs them in a follow-up.
|
|
17
|
+
|
|
18
|
+
## What belongs somewhere else
|
|
19
|
+
|
|
20
|
+
- Trigger source defs (`defineCronSource`, poll cadence) → `@keystrokehq/trigger`
|
|
21
|
+
- Running attachments, webhooks, poll HTTP → `@keystrokehq/runtime`
|
|
22
|
+
- `trigger_schedules` / `jobs` schema and queries → `@keystrokehq/database`
|
|
23
|
+
- Workflow/agent run logic → `@keystrokehq/workflow` / `@keystrokehq/agent` (server wires handlers)
|
|
24
|
+
|
|
25
|
+
## Where it sits
|
|
26
|
+
|
|
27
|
+
```mermaid
|
|
28
|
+
flowchart TB
|
|
29
|
+
scheduler["@keystrokehq/scheduler"]
|
|
30
|
+
|
|
31
|
+
database["@keystrokehq/database"]
|
|
32
|
+
trigger["@keystrokehq/trigger"]
|
|
33
|
+
|
|
34
|
+
scheduler --> database
|
|
35
|
+
scheduler --> trigger
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Allowed runtime deps:** `database`, `trigger`, `pg-boss`, `cron-parser` (via trigger).
|
|
39
|
+
|
|
40
|
+
**Forbidden:** `runtime`, `workflow`, `agent`, `action`, `config`, `build`, `cli`, integrations, HTTP frameworks. Scheduler must stay callable from runtime without circular imports.
|
|
41
|
+
|
|
42
|
+
**Depends on:** `database`, `trigger`, `pg-boss`, `cron-parser`.
|
|
43
|
+
|
|
44
|
+
**Used by:** `runtime` and `worker` (embedded worker + schedule ticker).
|
|
45
|
+
|
|
46
|
+
## Exports
|
|
47
|
+
|
|
48
|
+
Import from the package root (`@keystrokehq/scheduler`), not from `src/…`.
|
|
49
|
+
|
|
50
|
+
| Export | What it's for |
|
|
51
|
+
| ------------------------ | --------------------------------------------------------- |
|
|
52
|
+
| `createScheduler` | Production queue + schedule APIs |
|
|
53
|
+
| `SchedulerPlugin` | Pluggable queue backend contract |
|
|
54
|
+
| `defaultSchedulerPlugin` | pg-boss (Postgres) / DB polling (SQLite) |
|
|
55
|
+
| `createSharedScheduler` | Platform shared queue (honors `configureSharedScheduler`) |
|
|
56
|
+
| `createMemoryJobQueue` | Test / dev in-process queue |
|
|
57
|
+
| `Scheduler` | Full surface (`JobQueue` + schedule sync/ticker) |
|
|
58
|
+
| `JobQueue` | Enqueue + worker only (typing server overrides) |
|
|
59
|
+
| `JobHandler` | Process one claimed job payload |
|
|
60
|
+
| `EnqueueInput` | Build enqueue calls from server |
|
|
61
|
+
| `JobTrigger` | `"api"` \| `"cron"` \| `"webhook"` \| `"poll"` \| … |
|
|
62
|
+
| `StopFn` | Stop worker or schedule ticker |
|
|
63
|
+
| `MemoryJobQueueOptions` | `{ sync?: boolean }` for memory queue |
|
|
64
|
+
|
|
65
|
+
## Source layout
|
|
66
|
+
|
|
67
|
+
| File | What's in it |
|
|
68
|
+
| --------------------------- | ----------------------------------------------------------------- |
|
|
69
|
+
| `types.ts` | Job + scheduler types, retry backoff helper |
|
|
70
|
+
| `create-scheduler.ts` | `createScheduler`, `createJobQueue`, `wrapJobQueueAsScheduler` |
|
|
71
|
+
| `database-queue.ts` | SQLite / generic Postgres job table worker |
|
|
72
|
+
| `pg-boss-queue.ts` | Postgres pg-boss backend (exposes `boss` for native scheduling) |
|
|
73
|
+
| `pg-boss-trigger-scheduler.ts` | pg-boss native cron `TriggerScheduler` (no poll loop) |
|
|
74
|
+
| `database-trigger-scheduler.ts` | DB-ticker `TriggerScheduler` for the polling/SQLite backend |
|
|
75
|
+
| `memory.ts` | In-memory `JobQueue` |
|
|
76
|
+
| `sync-trigger-schedules.ts` | DB upsert for discovered cron/poll attachments |
|
|
77
|
+
| `resolve-schedule.ts` | Override-aware cron string (uses trigger's `resolveCronSchedule`) |
|
|
78
|
+
| `schedule-ticker.ts` | Claim due schedules → enqueue trigger jobs (polling backend) |
|
|
79
|
+
|
|
80
|
+
## Adding a feature?
|
|
81
|
+
|
|
82
|
+
1. New queue backend or retry/concurrency behavior? → this package (keep types in `types.ts`).
|
|
83
|
+
2. New trigger schedule expression rules? → `@keystrokehq/trigger` (`nextTriggerRunAt`, `resolveCronSchedule`).
|
|
84
|
+
3. New table or claim query? → `@keystrokehq/database`.
|
|
85
|
+
4. Who runs the job (workflow step, agent prompt, attachment)? → `@keystrokehq/runtime` job handlers.
|
|
86
|
+
|
|
87
|
+
## Example
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { createScheduler } from "@keystrokehq/scheduler";
|
|
91
|
+
import { initDatabase } from "@keystrokehq/database";
|
|
92
|
+
|
|
93
|
+
await initDatabase({ url: process.env.DATABASE_URL });
|
|
94
|
+
|
|
95
|
+
const scheduler = await createScheduler({ url: process.env.DATABASE_URL });
|
|
96
|
+
|
|
97
|
+
await scheduler.syncTriggerSchedules({
|
|
98
|
+
schedules: [{ attachmentKey: "daily-report:run", kind: "cron", schedule: "0 9 * * *" }],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const stopWorker = await scheduler.startWorker(async (job) => {
|
|
102
|
+
console.log(job.kind, job.targetId, job.trigger);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const stopTicker = await scheduler.startScheduleTicker();
|
|
106
|
+
|
|
107
|
+
// … later
|
|
108
|
+
await stopTicker();
|
|
109
|
+
await stopWorker();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Tests
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pnpm --filter @keystrokehq/scheduler test
|
|
116
|
+
pnpm --filter @keystrokehq/scheduler typecheck
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Unit: `*.test.ts`. Integration (`queue.int.test.ts`): Postgres pg-boss via `describePostgres`; SQLite DB queue uses in-memory DB.
|
|
120
|
+
|
|
121
|
+
## See also
|
|
122
|
+
|
|
123
|
+
- [README.md](../../README.md) — platform layer map
|
|
124
|
+
- [packages/server/src/server.ts](../server/src/server.ts) — wires scheduler at listen
|
|
125
|
+
- [packages/trigger/](../trigger/) — cron parsing and `nextTriggerRunAt`
|
|
126
|
+
- [packages/database/src/scheduler/](../database/src/scheduler/) — jobs + `trigger_schedules` queries
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
const DEFAULT_RETRY_DELAY_MS = 5e3;
|
|
3
|
+
function retryDelayMs(attempt) {
|
|
4
|
+
return DEFAULT_RETRY_DELAY_MS * 2 ** Math.max(0, attempt - 1);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/contract.ts
|
|
8
|
+
function defineSchedulerPlugin(plugin) {
|
|
9
|
+
return plugin;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
Object.defineProperty(exports, "DEFAULT_RETRY_DELAY_MS", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function() {
|
|
15
|
+
return DEFAULT_RETRY_DELAY_MS;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "defineSchedulerPlugin", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function() {
|
|
21
|
+
return defineSchedulerPlugin;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "retryDelayMs", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function() {
|
|
27
|
+
return retryDelayMs;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=contract-C5JvbyQ-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-C5JvbyQ-.cjs","names":[],"sources":["../src/types.ts","../src/contract.ts"],"sourcesContent":["export type JobKind =\n | \"workflow\"\n | \"agent\"\n | \"trigger\"\n | \"trigger-overview\"\n | \"workflow-canvas-annotations\"\n | \"workflow-overview\"\n | \"runtime\"\n | \"maintenance\";\n\nexport type JobTrigger = \"api\" | \"cron\" | \"webhook\" | \"poll\" | \"retry\" | \"prompt\";\n\n/**\n * Identifies a run that dispatched this job as a child. The parent metadata\n * survives the queue boundary so the child can resume its parent at a terminal\n * outcome without treating the child as a separately-billable dispatch.\n */\nexport type JobParent = {\n kind: \"workflow\" | \"agent\";\n runId: string;\n targetId: string;\n correlationId?: string;\n};\n\nexport type JobPayload = {\n kind: JobKind;\n targetId: string;\n runId: string;\n trigger: JobTrigger;\n payload: unknown;\n attempt: number;\n maxAttempts: number;\n /** True when this delivery is the final retry attempt. */\n exhaustedRetries?: boolean;\n scheduledAt: Date;\n jobId: string;\n /** Project scope for org-wide worker queues. */\n projectId?: string;\n /** Parent run that dispatched this child job, when applicable. */\n parent?: JobParent;\n /** Optional W3C trace context carrier (sibling of user payload). */\n traceContext?: Record<string, string>;\n};\n\nexport type EnqueueInput = {\n kind: JobKind;\n targetId: string;\n runId: string;\n trigger: JobTrigger;\n payload?: unknown;\n scheduledAt?: Date;\n attempt?: number;\n maxAttempts?: number;\n /** Dedupe key — pg-boss singletonKey / BullMQ jobId. */\n dedupeKey?: string;\n /** Project scope for org-wide worker queues. */\n projectId?: string;\n /** Parent run that dispatched this child job, when applicable. */\n parent?: JobParent;\n /** Optional W3C trace context carrier (sibling of user payload). */\n traceContext?: Record<string, string>;\n};\n\nexport type JobHandler = (job: JobPayload) => Promise<void>;\n\nexport type CancelHandler = (runId: string) => void | Promise<void>;\n\nexport type StopFn = () => Promise<void> | void;\n\nexport type WorkerOptions = {\n workerId?: string;\n pollIntervalMs?: number;\n leaseSweepIntervalMs?: number;\n};\n\nexport type JobQueue = {\n enqueue(input: EnqueueInput): Promise<string>;\n startWorker(handler: JobHandler, options?: WorkerOptions): Promise<StopFn>;\n /**\n * Temporarily lends a worker slot to a child while an agent job waits on it.\n * Backends without a hard concurrency cap may omit it.\n */\n withLentSlot?<T>(fn: () => Promise<T>): Promise<T>;\n publishCancel(runId: string): Promise<void>;\n subscribeCancel(handler: CancelHandler): Promise<StopFn>;\n};\n\nimport type { SchedulerPlugin, SchedulerScope, TriggerScheduleSpec } from \"./contract\";\n\nexport type { TriggerScheduleSpec };\n\nexport type CreateJobQueueOptions = {\n url?: string;\n dialect?: \"postgres\" | \"sqlite\";\n adapter?: JobQueue;\n plugin?: SchedulerPlugin;\n scope?: SchedulerScope;\n projectId?: string;\n organizationId?: string;\n};\n\nexport type ScheduleSyncOptions = {\n schedules: TriggerScheduleSpec[];\n scheduleOverrides?: {\n global?: string;\n byTrigger?: Record<string, string>;\n };\n};\n\nexport type ScheduleTickerOptions = {\n pollIntervalMs?: number;\n batchSize?: number;\n /** When `organization`, claims due schedules across all projects in the org schema. */\n scope?: \"project\" | \"organization\";\n};\n\nexport type Scheduler = JobQueue & {\n syncTriggerSchedules(options: ScheduleSyncOptions): Promise<void>;\n startScheduleTicker(options?: ScheduleTickerOptions): Promise<StopFn>;\n fireDueSchedules(asOf?: Date): Promise<number>;\n upsertTriggerSchedule?(\n spec: TriggerScheduleSpec,\n overrides?: ScheduleSyncOptions[\"scheduleOverrides\"],\n ): Promise<void>;\n removeTriggerSchedule?(triggerSlug: string, projectId?: string): Promise<void>;\n};\n\nexport type CreateSchedulerOptions = CreateJobQueueOptions;\n\nexport const DEFAULT_RETRY_DELAY_MS = 5_000;\n\nexport function retryDelayMs(attempt: number): number {\n return DEFAULT_RETRY_DELAY_MS * 2 ** Math.max(0, attempt - 1);\n}\n","export type {\n JobKind,\n JobTrigger,\n JobPayload,\n JobParent,\n EnqueueInput,\n JobHandler,\n CancelHandler,\n StopFn,\n WorkerOptions,\n JobQueue,\n} from \"./types\";\nexport { retryDelayMs, DEFAULT_RETRY_DELAY_MS } from \"./types\";\n\nimport type { JobQueue, StopFn } from \"./types\";\n\n/**\n * Inlined to keep the contract database-free — structurally identical to\n * `@keystrokehq/database`'s `DatabaseDialect`. Importing it from the database\n * package would re-introduce the dependency `./contract` exists to avoid.\n */\nexport type DatabaseDialect = \"postgres\" | \"sqlite\";\n\nexport type SchedulerScope = \"platform\" | \"project\" | \"organization\";\n\nexport type SchedulerPluginContext = {\n scope: SchedulerScope;\n url?: string;\n dialect?: DatabaseDialect;\n projectId?: string;\n organizationId?: string;\n};\n\nexport type TriggerScheduleSpec = {\n triggerSlug: string;\n kind: \"cron\" | \"poll\";\n schedule: string;\n /** IANA timezone for schedule wall-clock fields. When omitted, UTC. */\n timezone?: string;\n /** Project scope for org-wide worker queues. */\n projectId?: string;\n};\n\nexport type TriggerScheduleSyncOptions = {\n schedules: TriggerScheduleSpec[];\n scheduleOverrides?: {\n global?: string;\n byTrigger?: Record<string, string>;\n };\n};\n\nexport type TriggerSchedulerStartOptions = {\n pollIntervalMs?: number;\n batchSize?: number;\n /** When `organization`, claims due schedules across all projects in the org schema. */\n scope?: \"project\" | \"organization\";\n};\n\nexport type TriggerScheduler = {\n sync(options: TriggerScheduleSyncOptions): Promise<void>;\n start(options?: TriggerSchedulerStartOptions): Promise<StopFn>;\n /** Register or refresh one trigger schedule in the firing backend. */\n upsert?(\n spec: TriggerScheduleSpec,\n overrides?: TriggerScheduleSyncOptions[\"scheduleOverrides\"],\n ): Promise<void>;\n remove?(triggerSlug: string, projectId?: string): Promise<void>;\n fireDue?(asOf?: Date): Promise<number>;\n};\n\nexport type SchedulerPlugin = {\n name: string;\n createJobQueue(ctx: SchedulerPluginContext): Promise<JobQueue>;\n createTriggerScheduler?(ctx: SchedulerPluginContext, queue: JobQueue): Promise<TriggerScheduler>;\n};\n\nexport function defineSchedulerPlugin(plugin: SchedulerPlugin): SchedulerPlugin {\n return plugin;\n}\n"],"mappings":";AAiIA,MAAa,yBAAyB;AAEtC,SAAgB,aAAa,SAAyB;CACpD,OAAO,yBAAyB,KAAK,KAAK,IAAI,GAAG,UAAU,CAAC;AAC9D;;;ACzDA,SAAgB,sBAAsB,QAA0C;CAC9E,OAAO;AACT"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
const DEFAULT_RETRY_DELAY_MS = 5e3;
|
|
3
|
+
function retryDelayMs(attempt) {
|
|
4
|
+
return DEFAULT_RETRY_DELAY_MS * 2 ** Math.max(0, attempt - 1);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/contract.ts
|
|
8
|
+
function defineSchedulerPlugin(plugin) {
|
|
9
|
+
return plugin;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DEFAULT_RETRY_DELAY_MS as n, retryDelayMs as r, defineSchedulerPlugin as t };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=contract-E1QJBH6_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-E1QJBH6_.mjs","names":[],"sources":["../src/types.ts","../src/contract.ts"],"sourcesContent":["export type JobKind =\n | \"workflow\"\n | \"agent\"\n | \"trigger\"\n | \"trigger-overview\"\n | \"workflow-canvas-annotations\"\n | \"workflow-overview\"\n | \"runtime\"\n | \"maintenance\";\n\nexport type JobTrigger = \"api\" | \"cron\" | \"webhook\" | \"poll\" | \"retry\" | \"prompt\";\n\n/**\n * Identifies a run that dispatched this job as a child. The parent metadata\n * survives the queue boundary so the child can resume its parent at a terminal\n * outcome without treating the child as a separately-billable dispatch.\n */\nexport type JobParent = {\n kind: \"workflow\" | \"agent\";\n runId: string;\n targetId: string;\n correlationId?: string;\n};\n\nexport type JobPayload = {\n kind: JobKind;\n targetId: string;\n runId: string;\n trigger: JobTrigger;\n payload: unknown;\n attempt: number;\n maxAttempts: number;\n /** True when this delivery is the final retry attempt. */\n exhaustedRetries?: boolean;\n scheduledAt: Date;\n jobId: string;\n /** Project scope for org-wide worker queues. */\n projectId?: string;\n /** Parent run that dispatched this child job, when applicable. */\n parent?: JobParent;\n /** Optional W3C trace context carrier (sibling of user payload). */\n traceContext?: Record<string, string>;\n};\n\nexport type EnqueueInput = {\n kind: JobKind;\n targetId: string;\n runId: string;\n trigger: JobTrigger;\n payload?: unknown;\n scheduledAt?: Date;\n attempt?: number;\n maxAttempts?: number;\n /** Dedupe key — pg-boss singletonKey / BullMQ jobId. */\n dedupeKey?: string;\n /** Project scope for org-wide worker queues. */\n projectId?: string;\n /** Parent run that dispatched this child job, when applicable. */\n parent?: JobParent;\n /** Optional W3C trace context carrier (sibling of user payload). */\n traceContext?: Record<string, string>;\n};\n\nexport type JobHandler = (job: JobPayload) => Promise<void>;\n\nexport type CancelHandler = (runId: string) => void | Promise<void>;\n\nexport type StopFn = () => Promise<void> | void;\n\nexport type WorkerOptions = {\n workerId?: string;\n pollIntervalMs?: number;\n leaseSweepIntervalMs?: number;\n};\n\nexport type JobQueue = {\n enqueue(input: EnqueueInput): Promise<string>;\n startWorker(handler: JobHandler, options?: WorkerOptions): Promise<StopFn>;\n /**\n * Temporarily lends a worker slot to a child while an agent job waits on it.\n * Backends without a hard concurrency cap may omit it.\n */\n withLentSlot?<T>(fn: () => Promise<T>): Promise<T>;\n publishCancel(runId: string): Promise<void>;\n subscribeCancel(handler: CancelHandler): Promise<StopFn>;\n};\n\nimport type { SchedulerPlugin, SchedulerScope, TriggerScheduleSpec } from \"./contract\";\n\nexport type { TriggerScheduleSpec };\n\nexport type CreateJobQueueOptions = {\n url?: string;\n dialect?: \"postgres\" | \"sqlite\";\n adapter?: JobQueue;\n plugin?: SchedulerPlugin;\n scope?: SchedulerScope;\n projectId?: string;\n organizationId?: string;\n};\n\nexport type ScheduleSyncOptions = {\n schedules: TriggerScheduleSpec[];\n scheduleOverrides?: {\n global?: string;\n byTrigger?: Record<string, string>;\n };\n};\n\nexport type ScheduleTickerOptions = {\n pollIntervalMs?: number;\n batchSize?: number;\n /** When `organization`, claims due schedules across all projects in the org schema. */\n scope?: \"project\" | \"organization\";\n};\n\nexport type Scheduler = JobQueue & {\n syncTriggerSchedules(options: ScheduleSyncOptions): Promise<void>;\n startScheduleTicker(options?: ScheduleTickerOptions): Promise<StopFn>;\n fireDueSchedules(asOf?: Date): Promise<number>;\n upsertTriggerSchedule?(\n spec: TriggerScheduleSpec,\n overrides?: ScheduleSyncOptions[\"scheduleOverrides\"],\n ): Promise<void>;\n removeTriggerSchedule?(triggerSlug: string, projectId?: string): Promise<void>;\n};\n\nexport type CreateSchedulerOptions = CreateJobQueueOptions;\n\nexport const DEFAULT_RETRY_DELAY_MS = 5_000;\n\nexport function retryDelayMs(attempt: number): number {\n return DEFAULT_RETRY_DELAY_MS * 2 ** Math.max(0, attempt - 1);\n}\n","export type {\n JobKind,\n JobTrigger,\n JobPayload,\n JobParent,\n EnqueueInput,\n JobHandler,\n CancelHandler,\n StopFn,\n WorkerOptions,\n JobQueue,\n} from \"./types\";\nexport { retryDelayMs, DEFAULT_RETRY_DELAY_MS } from \"./types\";\n\nimport type { JobQueue, StopFn } from \"./types\";\n\n/**\n * Inlined to keep the contract database-free — structurally identical to\n * `@keystrokehq/database`'s `DatabaseDialect`. Importing it from the database\n * package would re-introduce the dependency `./contract` exists to avoid.\n */\nexport type DatabaseDialect = \"postgres\" | \"sqlite\";\n\nexport type SchedulerScope = \"platform\" | \"project\" | \"organization\";\n\nexport type SchedulerPluginContext = {\n scope: SchedulerScope;\n url?: string;\n dialect?: DatabaseDialect;\n projectId?: string;\n organizationId?: string;\n};\n\nexport type TriggerScheduleSpec = {\n triggerSlug: string;\n kind: \"cron\" | \"poll\";\n schedule: string;\n /** IANA timezone for schedule wall-clock fields. When omitted, UTC. */\n timezone?: string;\n /** Project scope for org-wide worker queues. */\n projectId?: string;\n};\n\nexport type TriggerScheduleSyncOptions = {\n schedules: TriggerScheduleSpec[];\n scheduleOverrides?: {\n global?: string;\n byTrigger?: Record<string, string>;\n };\n};\n\nexport type TriggerSchedulerStartOptions = {\n pollIntervalMs?: number;\n batchSize?: number;\n /** When `organization`, claims due schedules across all projects in the org schema. */\n scope?: \"project\" | \"organization\";\n};\n\nexport type TriggerScheduler = {\n sync(options: TriggerScheduleSyncOptions): Promise<void>;\n start(options?: TriggerSchedulerStartOptions): Promise<StopFn>;\n /** Register or refresh one trigger schedule in the firing backend. */\n upsert?(\n spec: TriggerScheduleSpec,\n overrides?: TriggerScheduleSyncOptions[\"scheduleOverrides\"],\n ): Promise<void>;\n remove?(triggerSlug: string, projectId?: string): Promise<void>;\n fireDue?(asOf?: Date): Promise<number>;\n};\n\nexport type SchedulerPlugin = {\n name: string;\n createJobQueue(ctx: SchedulerPluginContext): Promise<JobQueue>;\n createTriggerScheduler?(ctx: SchedulerPluginContext, queue: JobQueue): Promise<TriggerScheduler>;\n};\n\nexport function defineSchedulerPlugin(plugin: SchedulerPlugin): SchedulerPlugin {\n return plugin;\n}\n"],"mappings":";AAiIA,MAAa,yBAAyB;AAEtC,SAAgB,aAAa,SAAyB;CACpD,OAAO,yBAAyB,KAAK,KAAK,IAAI,GAAG,UAAU,CAAC;AAC9D;;;ACzDA,SAAgB,sBAAsB,QAA0C;CAC9E,OAAO;AACT"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type JobKind = "workflow" | "agent" | "trigger" | "trigger-overview" | "workflow-canvas-annotations" | "workflow-overview" | "runtime" | "maintenance";
|
|
3
|
+
type JobTrigger = "api" | "cron" | "webhook" | "poll" | "retry" | "prompt";
|
|
4
|
+
/**
|
|
5
|
+
* Identifies a run that dispatched this job as a child. The parent metadata
|
|
6
|
+
* survives the queue boundary so the child can resume its parent at a terminal
|
|
7
|
+
* outcome without treating the child as a separately-billable dispatch.
|
|
8
|
+
*/
|
|
9
|
+
type JobParent = {
|
|
10
|
+
kind: "workflow" | "agent";
|
|
11
|
+
runId: string;
|
|
12
|
+
targetId: string;
|
|
13
|
+
correlationId?: string;
|
|
14
|
+
};
|
|
15
|
+
type JobPayload = {
|
|
16
|
+
kind: JobKind;
|
|
17
|
+
targetId: string;
|
|
18
|
+
runId: string;
|
|
19
|
+
trigger: JobTrigger;
|
|
20
|
+
payload: unknown;
|
|
21
|
+
attempt: number;
|
|
22
|
+
maxAttempts: number; /** True when this delivery is the final retry attempt. */
|
|
23
|
+
exhaustedRetries?: boolean;
|
|
24
|
+
scheduledAt: Date;
|
|
25
|
+
jobId: string; /** Project scope for org-wide worker queues. */
|
|
26
|
+
projectId?: string; /** Parent run that dispatched this child job, when applicable. */
|
|
27
|
+
parent?: JobParent; /** Optional W3C trace context carrier (sibling of user payload). */
|
|
28
|
+
traceContext?: Record<string, string>;
|
|
29
|
+
};
|
|
30
|
+
type EnqueueInput = {
|
|
31
|
+
kind: JobKind;
|
|
32
|
+
targetId: string;
|
|
33
|
+
runId: string;
|
|
34
|
+
trigger: JobTrigger;
|
|
35
|
+
payload?: unknown;
|
|
36
|
+
scheduledAt?: Date;
|
|
37
|
+
attempt?: number;
|
|
38
|
+
maxAttempts?: number; /** Dedupe key — pg-boss singletonKey / BullMQ jobId. */
|
|
39
|
+
dedupeKey?: string; /** Project scope for org-wide worker queues. */
|
|
40
|
+
projectId?: string; /** Parent run that dispatched this child job, when applicable. */
|
|
41
|
+
parent?: JobParent; /** Optional W3C trace context carrier (sibling of user payload). */
|
|
42
|
+
traceContext?: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
type JobHandler = (job: JobPayload) => Promise<void>;
|
|
45
|
+
type CancelHandler = (runId: string) => void | Promise<void>;
|
|
46
|
+
type StopFn = () => Promise<void> | void;
|
|
47
|
+
type WorkerOptions = {
|
|
48
|
+
workerId?: string;
|
|
49
|
+
pollIntervalMs?: number;
|
|
50
|
+
leaseSweepIntervalMs?: number;
|
|
51
|
+
};
|
|
52
|
+
type JobQueue = {
|
|
53
|
+
enqueue(input: EnqueueInput): Promise<string>;
|
|
54
|
+
startWorker(handler: JobHandler, options?: WorkerOptions): Promise<StopFn>;
|
|
55
|
+
/**
|
|
56
|
+
* Temporarily lends a worker slot to a child while an agent job waits on it.
|
|
57
|
+
* Backends without a hard concurrency cap may omit it.
|
|
58
|
+
*/
|
|
59
|
+
withLentSlot?<T>(fn: () => Promise<T>): Promise<T>;
|
|
60
|
+
publishCancel(runId: string): Promise<void>;
|
|
61
|
+
subscribeCancel(handler: CancelHandler): Promise<StopFn>;
|
|
62
|
+
};
|
|
63
|
+
type CreateJobQueueOptions = {
|
|
64
|
+
url?: string;
|
|
65
|
+
dialect?: "postgres" | "sqlite";
|
|
66
|
+
adapter?: JobQueue;
|
|
67
|
+
plugin?: SchedulerPlugin;
|
|
68
|
+
scope?: SchedulerScope;
|
|
69
|
+
projectId?: string;
|
|
70
|
+
organizationId?: string;
|
|
71
|
+
};
|
|
72
|
+
type ScheduleSyncOptions = {
|
|
73
|
+
schedules: TriggerScheduleSpec[];
|
|
74
|
+
scheduleOverrides?: {
|
|
75
|
+
global?: string;
|
|
76
|
+
byTrigger?: Record<string, string>;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
type ScheduleTickerOptions = {
|
|
80
|
+
pollIntervalMs?: number;
|
|
81
|
+
batchSize?: number; /** When `organization`, claims due schedules across all projects in the org schema. */
|
|
82
|
+
scope?: "project" | "organization";
|
|
83
|
+
};
|
|
84
|
+
type Scheduler = JobQueue & {
|
|
85
|
+
syncTriggerSchedules(options: ScheduleSyncOptions): Promise<void>;
|
|
86
|
+
startScheduleTicker(options?: ScheduleTickerOptions): Promise<StopFn>;
|
|
87
|
+
fireDueSchedules(asOf?: Date): Promise<number>;
|
|
88
|
+
upsertTriggerSchedule?(spec: TriggerScheduleSpec, overrides?: ScheduleSyncOptions["scheduleOverrides"]): Promise<void>;
|
|
89
|
+
removeTriggerSchedule?(triggerSlug: string, projectId?: string): Promise<void>;
|
|
90
|
+
};
|
|
91
|
+
type CreateSchedulerOptions = CreateJobQueueOptions;
|
|
92
|
+
declare const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
93
|
+
declare function retryDelayMs(attempt: number): number;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/contract.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* Inlined to keep the contract database-free — structurally identical to
|
|
98
|
+
* `@keystrokehq/database`'s `DatabaseDialect`. Importing it from the database
|
|
99
|
+
* package would re-introduce the dependency `./contract` exists to avoid.
|
|
100
|
+
*/
|
|
101
|
+
type DatabaseDialect = "postgres" | "sqlite";
|
|
102
|
+
type SchedulerScope = "platform" | "project" | "organization";
|
|
103
|
+
type SchedulerPluginContext = {
|
|
104
|
+
scope: SchedulerScope;
|
|
105
|
+
url?: string;
|
|
106
|
+
dialect?: DatabaseDialect;
|
|
107
|
+
projectId?: string;
|
|
108
|
+
organizationId?: string;
|
|
109
|
+
};
|
|
110
|
+
type TriggerScheduleSpec = {
|
|
111
|
+
triggerSlug: string;
|
|
112
|
+
kind: "cron" | "poll";
|
|
113
|
+
schedule: string; /** IANA timezone for schedule wall-clock fields. When omitted, UTC. */
|
|
114
|
+
timezone?: string; /** Project scope for org-wide worker queues. */
|
|
115
|
+
projectId?: string;
|
|
116
|
+
};
|
|
117
|
+
type TriggerScheduleSyncOptions = {
|
|
118
|
+
schedules: TriggerScheduleSpec[];
|
|
119
|
+
scheduleOverrides?: {
|
|
120
|
+
global?: string;
|
|
121
|
+
byTrigger?: Record<string, string>;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
type TriggerSchedulerStartOptions = {
|
|
125
|
+
pollIntervalMs?: number;
|
|
126
|
+
batchSize?: number; /** When `organization`, claims due schedules across all projects in the org schema. */
|
|
127
|
+
scope?: "project" | "organization";
|
|
128
|
+
};
|
|
129
|
+
type TriggerScheduler = {
|
|
130
|
+
sync(options: TriggerScheduleSyncOptions): Promise<void>;
|
|
131
|
+
start(options?: TriggerSchedulerStartOptions): Promise<StopFn>; /** Register or refresh one trigger schedule in the firing backend. */
|
|
132
|
+
upsert?(spec: TriggerScheduleSpec, overrides?: TriggerScheduleSyncOptions["scheduleOverrides"]): Promise<void>;
|
|
133
|
+
remove?(triggerSlug: string, projectId?: string): Promise<void>;
|
|
134
|
+
fireDue?(asOf?: Date): Promise<number>;
|
|
135
|
+
};
|
|
136
|
+
type SchedulerPlugin = {
|
|
137
|
+
name: string;
|
|
138
|
+
createJobQueue(ctx: SchedulerPluginContext): Promise<JobQueue>;
|
|
139
|
+
createTriggerScheduler?(ctx: SchedulerPluginContext, queue: JobQueue): Promise<TriggerScheduler>;
|
|
140
|
+
};
|
|
141
|
+
declare function defineSchedulerPlugin(plugin: SchedulerPlugin): SchedulerPlugin;
|
|
142
|
+
//#endregion
|
|
143
|
+
export { Scheduler as C, retryDelayMs as E, ScheduleTickerOptions as S, WorkerOptions as T, JobParent as _, TriggerScheduleSpec as a, JobTrigger as b, TriggerSchedulerStartOptions as c, CreateJobQueueOptions as d, CreateSchedulerOptions as f, JobKind as g, JobHandler as h, SchedulerScope as i, defineSchedulerPlugin as l, EnqueueInput as m, SchedulerPlugin as n, TriggerScheduleSyncOptions as o, DEFAULT_RETRY_DELAY_MS as p, SchedulerPluginContext as r, TriggerScheduler as s, DatabaseDialect as t, CancelHandler as u, JobPayload as v, StopFn as w, ScheduleSyncOptions as x, JobQueue as y };
|
|
144
|
+
//# sourceMappingURL=contract-GpxHe4g6.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-GpxHe4g6.d.cts","names":[],"sources":["../src/types.ts","../src/contract.ts"],"mappings":";KAAY,OAAA;AAAA,KAUA,UAAA;;;;AAVO;AAUnB;KAOY,SAAA;EACV,IAAA;EACA,KAAA;EACA,QAAA;EACA,aAAA;AAAA;AAAA,KAGU,UAAA;EACV,IAAA,EAAM,OAAA;EACN,QAAA;EACA,KAAA;EACA,OAAA,EAAS,UAAA;EACT,OAAA;EACA,OAAA;EACA,WAAA,UAPU;EASV,gBAAA;EACA,WAAA,EAAa,IAAA;EACb,KAAA,UAPS;EAST,SAAA,WAES;EAAT,MAAA,GAAS,SAAA,EAEY;EAArB,YAAA,GAAe,MAAA;AAAA;AAAA,KAGL,YAAA;EACV,IAAA,EAAM,OAAA;EACN,QAAA;EACA,KAAA;EACA,OAAA,EAAS,UAAA;EACT,OAAA;EACA,WAAA,GAAc,IAAA;EACd,OAAA;EACA,WAAA,WAlBA;EAoBA,SAAA,WAnBA;EAqBA,SAAA,WAjBA;EAmBA,MAAA,GAAS,SAAA,EAjBT;EAmBA,YAAA,GAAe,MAAA;AAAA;AAAA,KAGL,UAAA,IAAc,GAAA,EAAK,UAAA,KAAe,OAAO;AAAA,KAEzC,aAAA,IAAiB,KAAA,oBAAyB,OAAO;AAAA,KAEjD,MAAA,SAAe,OAAO;AAAA,KAEtB,aAAA;EACV,QAAA;EACA,cAAA;EACA,oBAAA;AAAA;AAAA,KAGU,QAAA;EACV,OAAA,CAAQ,KAAA,EAAO,YAAA,GAAe,OAAA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ECcV,QAAA;EAEA,SAAA;AAAA;AAAA,KAGU,0BAAA;EACV,SAAA,EAAW,mBAAA;EACX,iBAAA;IACE,MAAA;IACA,SAAA,GAAY,MAAM;EAAA;AAAA;AAAA,KAIV,4BAAA;EACV,cAAA;EACA,SAAA,WDzBS;EC2BT,KAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA,CAAK,OAAA,EAAS,0BAAA,GAA6B,OAAA;EAC3C,KAAA,CAAM,OAAA,GAAU,4BAAA,GAA+B,OAAA,CAAQ,MAAA,GD1B1C;EC4Bb,MAAA,EACE,IAAA,EAAM,mBAAA,EACN,SAAA,GAAY,0BAAA,wBACX,OAAA;EACH,MAAA,EAAQ,WAAA,UAAqB,SAAA,YAAqB,OAAA;EAClD,OAAA,EAAS,IAAA,GAAO,IAAA,GAAO,OAAA;AAAA;AAAA,KAGb,eAAA;EACV,IAAA;EACA,cAAA,CAAe,GAAA,EAAK,sBAAA,GAAyB,OAAA,CAAQ,QAAA;EACrD,sBAAA,EAAwB,GAAA,EAAK,sBAAA,EAAwB,KAAA,EAAO,QAAA,GAAW,OAAA,CAAQ,gBAAA;AAAA;AAAA,iBAGjE,qBAAA,CAAsB,MAAA,EAAQ,eAAA,GAAkB,eAAe"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type JobKind = "workflow" | "agent" | "trigger" | "trigger-overview" | "workflow-canvas-annotations" | "workflow-overview" | "runtime" | "maintenance";
|
|
3
|
+
type JobTrigger = "api" | "cron" | "webhook" | "poll" | "retry" | "prompt";
|
|
4
|
+
/**
|
|
5
|
+
* Identifies a run that dispatched this job as a child. The parent metadata
|
|
6
|
+
* survives the queue boundary so the child can resume its parent at a terminal
|
|
7
|
+
* outcome without treating the child as a separately-billable dispatch.
|
|
8
|
+
*/
|
|
9
|
+
type JobParent = {
|
|
10
|
+
kind: "workflow" | "agent";
|
|
11
|
+
runId: string;
|
|
12
|
+
targetId: string;
|
|
13
|
+
correlationId?: string;
|
|
14
|
+
};
|
|
15
|
+
type JobPayload = {
|
|
16
|
+
kind: JobKind;
|
|
17
|
+
targetId: string;
|
|
18
|
+
runId: string;
|
|
19
|
+
trigger: JobTrigger;
|
|
20
|
+
payload: unknown;
|
|
21
|
+
attempt: number;
|
|
22
|
+
maxAttempts: number; /** True when this delivery is the final retry attempt. */
|
|
23
|
+
exhaustedRetries?: boolean;
|
|
24
|
+
scheduledAt: Date;
|
|
25
|
+
jobId: string; /** Project scope for org-wide worker queues. */
|
|
26
|
+
projectId?: string; /** Parent run that dispatched this child job, when applicable. */
|
|
27
|
+
parent?: JobParent; /** Optional W3C trace context carrier (sibling of user payload). */
|
|
28
|
+
traceContext?: Record<string, string>;
|
|
29
|
+
};
|
|
30
|
+
type EnqueueInput = {
|
|
31
|
+
kind: JobKind;
|
|
32
|
+
targetId: string;
|
|
33
|
+
runId: string;
|
|
34
|
+
trigger: JobTrigger;
|
|
35
|
+
payload?: unknown;
|
|
36
|
+
scheduledAt?: Date;
|
|
37
|
+
attempt?: number;
|
|
38
|
+
maxAttempts?: number; /** Dedupe key — pg-boss singletonKey / BullMQ jobId. */
|
|
39
|
+
dedupeKey?: string; /** Project scope for org-wide worker queues. */
|
|
40
|
+
projectId?: string; /** Parent run that dispatched this child job, when applicable. */
|
|
41
|
+
parent?: JobParent; /** Optional W3C trace context carrier (sibling of user payload). */
|
|
42
|
+
traceContext?: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
type JobHandler = (job: JobPayload) => Promise<void>;
|
|
45
|
+
type CancelHandler = (runId: string) => void | Promise<void>;
|
|
46
|
+
type StopFn = () => Promise<void> | void;
|
|
47
|
+
type WorkerOptions = {
|
|
48
|
+
workerId?: string;
|
|
49
|
+
pollIntervalMs?: number;
|
|
50
|
+
leaseSweepIntervalMs?: number;
|
|
51
|
+
};
|
|
52
|
+
type JobQueue = {
|
|
53
|
+
enqueue(input: EnqueueInput): Promise<string>;
|
|
54
|
+
startWorker(handler: JobHandler, options?: WorkerOptions): Promise<StopFn>;
|
|
55
|
+
/**
|
|
56
|
+
* Temporarily lends a worker slot to a child while an agent job waits on it.
|
|
57
|
+
* Backends without a hard concurrency cap may omit it.
|
|
58
|
+
*/
|
|
59
|
+
withLentSlot?<T>(fn: () => Promise<T>): Promise<T>;
|
|
60
|
+
publishCancel(runId: string): Promise<void>;
|
|
61
|
+
subscribeCancel(handler: CancelHandler): Promise<StopFn>;
|
|
62
|
+
};
|
|
63
|
+
type CreateJobQueueOptions = {
|
|
64
|
+
url?: string;
|
|
65
|
+
dialect?: "postgres" | "sqlite";
|
|
66
|
+
adapter?: JobQueue;
|
|
67
|
+
plugin?: SchedulerPlugin;
|
|
68
|
+
scope?: SchedulerScope;
|
|
69
|
+
projectId?: string;
|
|
70
|
+
organizationId?: string;
|
|
71
|
+
};
|
|
72
|
+
type ScheduleSyncOptions = {
|
|
73
|
+
schedules: TriggerScheduleSpec[];
|
|
74
|
+
scheduleOverrides?: {
|
|
75
|
+
global?: string;
|
|
76
|
+
byTrigger?: Record<string, string>;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
type ScheduleTickerOptions = {
|
|
80
|
+
pollIntervalMs?: number;
|
|
81
|
+
batchSize?: number; /** When `organization`, claims due schedules across all projects in the org schema. */
|
|
82
|
+
scope?: "project" | "organization";
|
|
83
|
+
};
|
|
84
|
+
type Scheduler = JobQueue & {
|
|
85
|
+
syncTriggerSchedules(options: ScheduleSyncOptions): Promise<void>;
|
|
86
|
+
startScheduleTicker(options?: ScheduleTickerOptions): Promise<StopFn>;
|
|
87
|
+
fireDueSchedules(asOf?: Date): Promise<number>;
|
|
88
|
+
upsertTriggerSchedule?(spec: TriggerScheduleSpec, overrides?: ScheduleSyncOptions["scheduleOverrides"]): Promise<void>;
|
|
89
|
+
removeTriggerSchedule?(triggerSlug: string, projectId?: string): Promise<void>;
|
|
90
|
+
};
|
|
91
|
+
type CreateSchedulerOptions = CreateJobQueueOptions;
|
|
92
|
+
declare const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
93
|
+
declare function retryDelayMs(attempt: number): number;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/contract.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* Inlined to keep the contract database-free — structurally identical to
|
|
98
|
+
* `@keystrokehq/database`'s `DatabaseDialect`. Importing it from the database
|
|
99
|
+
* package would re-introduce the dependency `./contract` exists to avoid.
|
|
100
|
+
*/
|
|
101
|
+
type DatabaseDialect = "postgres" | "sqlite";
|
|
102
|
+
type SchedulerScope = "platform" | "project" | "organization";
|
|
103
|
+
type SchedulerPluginContext = {
|
|
104
|
+
scope: SchedulerScope;
|
|
105
|
+
url?: string;
|
|
106
|
+
dialect?: DatabaseDialect;
|
|
107
|
+
projectId?: string;
|
|
108
|
+
organizationId?: string;
|
|
109
|
+
};
|
|
110
|
+
type TriggerScheduleSpec = {
|
|
111
|
+
triggerSlug: string;
|
|
112
|
+
kind: "cron" | "poll";
|
|
113
|
+
schedule: string; /** IANA timezone for schedule wall-clock fields. When omitted, UTC. */
|
|
114
|
+
timezone?: string; /** Project scope for org-wide worker queues. */
|
|
115
|
+
projectId?: string;
|
|
116
|
+
};
|
|
117
|
+
type TriggerScheduleSyncOptions = {
|
|
118
|
+
schedules: TriggerScheduleSpec[];
|
|
119
|
+
scheduleOverrides?: {
|
|
120
|
+
global?: string;
|
|
121
|
+
byTrigger?: Record<string, string>;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
type TriggerSchedulerStartOptions = {
|
|
125
|
+
pollIntervalMs?: number;
|
|
126
|
+
batchSize?: number; /** When `organization`, claims due schedules across all projects in the org schema. */
|
|
127
|
+
scope?: "project" | "organization";
|
|
128
|
+
};
|
|
129
|
+
type TriggerScheduler = {
|
|
130
|
+
sync(options: TriggerScheduleSyncOptions): Promise<void>;
|
|
131
|
+
start(options?: TriggerSchedulerStartOptions): Promise<StopFn>; /** Register or refresh one trigger schedule in the firing backend. */
|
|
132
|
+
upsert?(spec: TriggerScheduleSpec, overrides?: TriggerScheduleSyncOptions["scheduleOverrides"]): Promise<void>;
|
|
133
|
+
remove?(triggerSlug: string, projectId?: string): Promise<void>;
|
|
134
|
+
fireDue?(asOf?: Date): Promise<number>;
|
|
135
|
+
};
|
|
136
|
+
type SchedulerPlugin = {
|
|
137
|
+
name: string;
|
|
138
|
+
createJobQueue(ctx: SchedulerPluginContext): Promise<JobQueue>;
|
|
139
|
+
createTriggerScheduler?(ctx: SchedulerPluginContext, queue: JobQueue): Promise<TriggerScheduler>;
|
|
140
|
+
};
|
|
141
|
+
declare function defineSchedulerPlugin(plugin: SchedulerPlugin): SchedulerPlugin;
|
|
142
|
+
//#endregion
|
|
143
|
+
export { Scheduler as C, retryDelayMs as E, ScheduleTickerOptions as S, WorkerOptions as T, JobParent as _, TriggerScheduleSpec as a, JobTrigger as b, TriggerSchedulerStartOptions as c, CreateJobQueueOptions as d, CreateSchedulerOptions as f, JobKind as g, JobHandler as h, SchedulerScope as i, defineSchedulerPlugin as l, EnqueueInput as m, SchedulerPlugin as n, TriggerScheduleSyncOptions as o, DEFAULT_RETRY_DELAY_MS as p, SchedulerPluginContext as r, TriggerScheduler as s, DatabaseDialect as t, CancelHandler as u, JobPayload as v, StopFn as w, ScheduleSyncOptions as x, JobQueue as y };
|
|
144
|
+
//# sourceMappingURL=contract-GpxHe4g6.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-GpxHe4g6.d.mts","names":[],"sources":["../src/types.ts","../src/contract.ts"],"mappings":";KAAY,OAAA;AAAA,KAUA,UAAA;;;;AAVO;AAUnB;KAOY,SAAA;EACV,IAAA;EACA,KAAA;EACA,QAAA;EACA,aAAA;AAAA;AAAA,KAGU,UAAA;EACV,IAAA,EAAM,OAAA;EACN,QAAA;EACA,KAAA;EACA,OAAA,EAAS,UAAA;EACT,OAAA;EACA,OAAA;EACA,WAAA,UAPU;EASV,gBAAA;EACA,WAAA,EAAa,IAAA;EACb,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A,EAAK,sBAAA,EAAwB,KAAA,EAAO,QAAA,GAAW,OAAA,CAAQ,gBAAA;AAAA;AAAA,iBAGjE,qBAAA,CAAsB,MAAA,EAAQ,eAAA,GAAkB,eAAe"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_contract = require("./contract-C5JvbyQ-.cjs");
|
|
3
|
+
exports.DEFAULT_RETRY_DELAY_MS = require_contract.DEFAULT_RETRY_DELAY_MS;
|
|
4
|
+
exports.defineSchedulerPlugin = require_contract.defineSchedulerPlugin;
|
|
5
|
+
exports.retryDelayMs = require_contract.retryDelayMs;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { E as retryDelayMs, T as WorkerOptions, _ as JobParent, a as TriggerScheduleSpec, b as JobTrigger, c as TriggerSchedulerStartOptions, g as JobKind, h as JobHandler, i as SchedulerScope, l as defineSchedulerPlugin, m as EnqueueInput, n as SchedulerPlugin, o as TriggerScheduleSyncOptions, p as DEFAULT_RETRY_DELAY_MS, r as SchedulerPluginContext, s as TriggerScheduler, t as DatabaseDialect, u as CancelHandler, v as JobPayload, w as StopFn, y as JobQueue } from "./contract-GpxHe4g6.cjs";
|
|
2
|
+
export { type CancelHandler, DEFAULT_RETRY_DELAY_MS, DatabaseDialect, type EnqueueInput, type JobHandler, type JobKind, type JobParent, type JobPayload, type JobQueue, type JobTrigger, SchedulerPlugin, SchedulerPluginContext, SchedulerScope, type StopFn, TriggerScheduleSpec, TriggerScheduleSyncOptions, TriggerScheduler, TriggerSchedulerStartOptions, type WorkerOptions, defineSchedulerPlugin, retryDelayMs };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { E as retryDelayMs, T as WorkerOptions, _ as JobParent, a as TriggerScheduleSpec, b as JobTrigger, c as TriggerSchedulerStartOptions, g as JobKind, h as JobHandler, i as SchedulerScope, l as defineSchedulerPlugin, m as EnqueueInput, n as SchedulerPlugin, o as TriggerScheduleSyncOptions, p as DEFAULT_RETRY_DELAY_MS, r as SchedulerPluginContext, s as TriggerScheduler, t as DatabaseDialect, u as CancelHandler, v as JobPayload, w as StopFn, y as JobQueue } from "./contract-GpxHe4g6.mjs";
|
|
2
|
+
export { type CancelHandler, DEFAULT_RETRY_DELAY_MS, DatabaseDialect, type EnqueueInput, type JobHandler, type JobKind, type JobParent, type JobPayload, type JobQueue, type JobTrigger, SchedulerPlugin, SchedulerPluginContext, SchedulerScope, type StopFn, TriggerScheduleSpec, TriggerScheduleSyncOptions, TriggerScheduler, TriggerSchedulerStartOptions, type WorkerOptions, defineSchedulerPlugin, retryDelayMs };
|