@lunora/scheduler 1.0.0-alpha.45 → 1.0.0-alpha.47
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/README.md +1 -1
- package/dist/index.d.mts +75 -31
- package/dist/index.d.ts +75 -31
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/createScheduler-CW8pPy0j.mjs +1 -0
- package/dist/packem_shared/{createSchedulerHost-BnNZ3raF.mjs → createSchedulerHost-B-5nnRt8.mjs} +1 -1
- package/package.json +3 -3
- package/dist/packem_shared/createScheduler-Bh_lfToR.mjs +0 -1
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ import { api } from "@/lunora/_generated/api";
|
|
|
83
83
|
|
|
84
84
|
const scheduler = createScheduler({ namespace: env.SCHEDULER, originUrl: "https://app.acme.test" });
|
|
85
85
|
|
|
86
|
-
const
|
|
86
|
+
const id = await scheduler.runAfter(5 * 60_000, api.email.sendReminder, { userId: "u-1" });
|
|
87
87
|
await scheduler.cancel(id);
|
|
88
88
|
```
|
|
89
89
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import { SchedulerHost } from '@lunora/platform';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* direct dependency to keep this package usable from the codegen pipeline
|
|
6
|
-
* itself.
|
|
3
|
+
* The generated function-reference type, shared by every package that needs to
|
|
4
|
+
* infer a call's args or return from `api.<file>.<fn>`.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* This lives in `shared/` rather than in one package because the consumers span
|
|
7
|
+
* a dependency boundary they must not cross: `@lunora/scheduler` and
|
|
8
|
+
* `@lunora/workflow` accept a reference in `runAfter`/`runAt`/`step.run*` but
|
|
9
|
+
* cannot depend on `@lunora/client`, which is a browser package. Each of them
|
|
10
|
+
* previously hand-copied this declaration, and both copies silently rotted when
|
|
11
|
+
* the phantom carrier was renamed — the conditional matched an OPTIONAL property
|
|
12
|
+
* that no longer existed, so `ArgsOf<F>` quietly resolved to `unknown` and every
|
|
13
|
+
* `step.run(ref, args)` in the repo lost its arg checking without a single error.
|
|
14
|
+
*
|
|
15
|
+
* `shared/` is the repo's answer to exactly that shape: bundler-inlined,
|
|
16
|
+
* zero-dependency source imported by relative path, so it creates no runtime
|
|
17
|
+
* edge between the packages that inline it. Being ONE declaration, there is
|
|
18
|
+
* nothing to keep in lockstep and no drift test to write.
|
|
10
19
|
*/
|
|
11
|
-
|
|
20
|
+
/** The registered function kinds a {@link FunctionReference} can describe. `stream` is a query that yields multiple frames over the WS. */
|
|
21
|
+
type FunctionKind = "action" | "mutation" | "query" | "stream";
|
|
22
|
+
/**
|
|
23
|
+
* Opaque reference to a registered function emitted by `@lunora/codegen`.
|
|
24
|
+
*
|
|
25
|
+
* At runtime it carries the `<file>:<function>` identifier in `__lunoraRef`.
|
|
26
|
+
* Generated declarations decorate this with phantom type parameters so callers
|
|
27
|
+
* can infer args / return values per call site.
|
|
28
|
+
*/
|
|
29
|
+
interface FunctionReference<Kind extends FunctionKind = FunctionKind, Args = unknown, Return = unknown> {
|
|
30
|
+
/**
|
|
31
|
+
* Phantom marker carrying the `Kind`/`Args`/`Return` type parameters for
|
|
32
|
+
* inference. Never present at runtime; declared as a covariant (output)
|
|
33
|
+
* position so a concrete reference stays assignable to a widened one.
|
|
34
|
+
*/
|
|
35
|
+
readonly __lunoraPhantom?: {
|
|
36
|
+
args: Args;
|
|
37
|
+
kind: Kind;
|
|
38
|
+
returns: Return;
|
|
39
|
+
};
|
|
12
40
|
readonly __lunoraRef: string;
|
|
13
|
-
/** Marker phantom type — discriminates queries / mutations / actions. */
|
|
14
|
-
readonly _kind?: "query" | "mutation" | "action";
|
|
15
41
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} ? A : Record<string, unknown>;
|
|
42
|
+
/** Extract the args type from a {@link FunctionReference}. */
|
|
43
|
+
type ArgsOf<F> = F extends FunctionReference<infer _K, infer A, infer _R> ? A : never;
|
|
19
44
|
/**
|
|
20
45
|
* Typed reference to a Lunora durable workflow — either the generated
|
|
21
46
|
* `workflows.<name>` reference object (`_generated/api.ts`, which carries the
|
|
@@ -42,19 +67,30 @@ interface WorkflowReference<Params = Record<string, unknown>> {
|
|
|
42
67
|
/** The workflow's export/stable name (present on a generated ref; a `defineWorkflow({ name })` override otherwise). */
|
|
43
68
|
readonly name?: string;
|
|
44
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A function reference a scheduler or workpool may target.
|
|
72
|
+
*
|
|
73
|
+
* `stream` is excluded deliberately, and the exclusion is load-bearing rather
|
|
74
|
+
* than tidiness: a scheduled job is dispatched as an ordinary `/rpc` call, and
|
|
75
|
+
* the function runner cannot execute a stream function (see
|
|
76
|
+
* `create-worker.ts`'s registry note). Accepting one compiles a job that is
|
|
77
|
+
* guaranteed to fail when its alarm fires, long after the call site that
|
|
78
|
+
* scheduled it.
|
|
79
|
+
*/
|
|
80
|
+
type SchedulableReference<Args = unknown, Return = unknown> = FunctionReference<Exclude<FunctionKind, "stream">, Args, Return>;
|
|
45
81
|
/** A cron job's target: either a one-shot function dispatch or a durable workflow start. */
|
|
46
|
-
type CronTarget =
|
|
82
|
+
type CronTarget = SchedulableReference | WorkflowReference;
|
|
47
83
|
/** The arguments a cron's target accepts: a workflow's inferred `params`, else an open record (function args aren't inferred). */
|
|
48
84
|
type CronTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : Record<string, unknown>;
|
|
49
85
|
/**
|
|
50
86
|
* The arguments a one-shot schedule target ({@link Scheduler.runAfter} /
|
|
51
|
-
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it
|
|
52
|
-
* {@link FunctionReference}'s
|
|
53
|
-
* {@link WorkflowReference}'s
|
|
54
|
-
*
|
|
55
|
-
* `params`.
|
|
87
|
+
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it resolves a
|
|
88
|
+
* {@link FunctionReference}'s `args` through {@link ArgsOf} as well as a
|
|
89
|
+
* {@link WorkflowReference}'s `params`, so scheduling a generated function
|
|
90
|
+
* reference is arg-checked against that function's validator while scheduling a
|
|
91
|
+
* workflow/agent is checked against its `params`.
|
|
56
92
|
*/
|
|
57
|
-
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends
|
|
93
|
+
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends SchedulableReference ? ArgsOf<T> : Record<string, unknown>;
|
|
58
94
|
/** Narrow a {@link CronTarget} to a {@link WorkflowReference} by its runtime brand. */
|
|
59
95
|
declare const isWorkflowReference: (target: unknown) => target is WorkflowReference;
|
|
60
96
|
/**
|
|
@@ -172,16 +208,24 @@ interface Scheduler {
|
|
|
172
208
|
* `agents.<name>` ref — which starts a fresh instance on fire (args become
|
|
173
209
|
* its `params`). {@link ScheduleTargetArgs} infers the accepted args from
|
|
174
210
|
* whichever target was passed.
|
|
211
|
+
*
|
|
212
|
+
* **Resolves the job id, a bare string** — the same value `cancel`/`get`
|
|
213
|
+
* take, and the same value the `ctx.scheduler` surface promises. This object
|
|
214
|
+
* IS `ctx.scheduler` on the shard side (codegen installs it behind
|
|
215
|
+
* `SchedulerLike`, whose `runAfter`/`runAt` are declared `Promise<string>`),
|
|
216
|
+
* so resolving a `{ id, scheduledFor }` record here handed mutations an
|
|
217
|
+
* object where every other gate — `@lunora/server`'s `Scheduler`,
|
|
218
|
+
* `@lunora/shard-engine`'s `SchedulerLike`, `@lunora/runtime`'s httpAction
|
|
219
|
+
* ctx, and the docs — said string. Nothing caught it, because the install is
|
|
220
|
+
* a cast: apps wrote the object into a string column and `cancel(id)`
|
|
221
|
+
* answered `{ cancelled: false }` with no error anywhere.
|
|
222
|
+
*
|
|
223
|
+
* The fire instant is not lost: `runAt` was handed it, and a caller that
|
|
224
|
+
* needs it back reads `scheduledFor` off {@link Scheduler.get}.
|
|
175
225
|
*/
|
|
176
|
-
runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}>;
|
|
180
|
-
/** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. */
|
|
181
|
-
runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<{
|
|
182
|
-
id: string;
|
|
183
|
-
scheduledFor: number;
|
|
184
|
-
}>;
|
|
226
|
+
runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
|
|
227
|
+
/** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. Resolves the job id. */
|
|
228
|
+
runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
|
|
185
229
|
}
|
|
186
230
|
/**
|
|
187
231
|
* Cloudflare Durable Object data-residency jurisdiction. Widening union —
|
|
@@ -268,7 +312,7 @@ interface Workpool {
|
|
|
268
312
|
* and the time it was scheduled for (it may not run immediately if the pool
|
|
269
313
|
* is at capacity).
|
|
270
314
|
*/
|
|
271
|
-
enqueue: <F extends
|
|
315
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: EnqueueOptions) => Promise<{
|
|
272
316
|
id: string;
|
|
273
317
|
scheduledFor: number;
|
|
274
318
|
}>;
|
|
@@ -348,7 +392,7 @@ interface QueueWorkpoolOptions {
|
|
|
348
392
|
*/
|
|
349
393
|
interface QueueWorkpool {
|
|
350
394
|
/** Enqueue a single `fn(args)` dispatch. */
|
|
351
|
-
enqueue: <F extends
|
|
395
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: QueueEnqueueOptions) => Promise<void>;
|
|
352
396
|
/** Enqueue many dispatches in one `sendBatch`. Each job names its function `ref`. */
|
|
353
397
|
enqueueBatch: (jobs: ReadonlyArray<{
|
|
354
398
|
args?: Record<string, unknown>;
|
|
@@ -1005,4 +1049,4 @@ declare const warnIfSecondsLeading: (schedule: string, context: string) => void;
|
|
|
1005
1049
|
* {@link warnIfSecondsLeading}.
|
|
1006
1050
|
*/
|
|
1007
1051
|
declare const assertValidCronExpression: (schedule: string, context?: string) => void;
|
|
1008
|
-
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|
|
1052
|
+
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionKind, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import { SchedulerHost } from '@lunora/platform';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* direct dependency to keep this package usable from the codegen pipeline
|
|
6
|
-
* itself.
|
|
3
|
+
* The generated function-reference type, shared by every package that needs to
|
|
4
|
+
* infer a call's args or return from `api.<file>.<fn>`.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* This lives in `shared/` rather than in one package because the consumers span
|
|
7
|
+
* a dependency boundary they must not cross: `@lunora/scheduler` and
|
|
8
|
+
* `@lunora/workflow` accept a reference in `runAfter`/`runAt`/`step.run*` but
|
|
9
|
+
* cannot depend on `@lunora/client`, which is a browser package. Each of them
|
|
10
|
+
* previously hand-copied this declaration, and both copies silently rotted when
|
|
11
|
+
* the phantom carrier was renamed — the conditional matched an OPTIONAL property
|
|
12
|
+
* that no longer existed, so `ArgsOf<F>` quietly resolved to `unknown` and every
|
|
13
|
+
* `step.run(ref, args)` in the repo lost its arg checking without a single error.
|
|
14
|
+
*
|
|
15
|
+
* `shared/` is the repo's answer to exactly that shape: bundler-inlined,
|
|
16
|
+
* zero-dependency source imported by relative path, so it creates no runtime
|
|
17
|
+
* edge between the packages that inline it. Being ONE declaration, there is
|
|
18
|
+
* nothing to keep in lockstep and no drift test to write.
|
|
10
19
|
*/
|
|
11
|
-
|
|
20
|
+
/** The registered function kinds a {@link FunctionReference} can describe. `stream` is a query that yields multiple frames over the WS. */
|
|
21
|
+
type FunctionKind = "action" | "mutation" | "query" | "stream";
|
|
22
|
+
/**
|
|
23
|
+
* Opaque reference to a registered function emitted by `@lunora/codegen`.
|
|
24
|
+
*
|
|
25
|
+
* At runtime it carries the `<file>:<function>` identifier in `__lunoraRef`.
|
|
26
|
+
* Generated declarations decorate this with phantom type parameters so callers
|
|
27
|
+
* can infer args / return values per call site.
|
|
28
|
+
*/
|
|
29
|
+
interface FunctionReference<Kind extends FunctionKind = FunctionKind, Args = unknown, Return = unknown> {
|
|
30
|
+
/**
|
|
31
|
+
* Phantom marker carrying the `Kind`/`Args`/`Return` type parameters for
|
|
32
|
+
* inference. Never present at runtime; declared as a covariant (output)
|
|
33
|
+
* position so a concrete reference stays assignable to a widened one.
|
|
34
|
+
*/
|
|
35
|
+
readonly __lunoraPhantom?: {
|
|
36
|
+
args: Args;
|
|
37
|
+
kind: Kind;
|
|
38
|
+
returns: Return;
|
|
39
|
+
};
|
|
12
40
|
readonly __lunoraRef: string;
|
|
13
|
-
/** Marker phantom type — discriminates queries / mutations / actions. */
|
|
14
|
-
readonly _kind?: "query" | "mutation" | "action";
|
|
15
41
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} ? A : Record<string, unknown>;
|
|
42
|
+
/** Extract the args type from a {@link FunctionReference}. */
|
|
43
|
+
type ArgsOf<F> = F extends FunctionReference<infer _K, infer A, infer _R> ? A : never;
|
|
19
44
|
/**
|
|
20
45
|
* Typed reference to a Lunora durable workflow — either the generated
|
|
21
46
|
* `workflows.<name>` reference object (`_generated/api.ts`, which carries the
|
|
@@ -42,19 +67,30 @@ interface WorkflowReference<Params = Record<string, unknown>> {
|
|
|
42
67
|
/** The workflow's export/stable name (present on a generated ref; a `defineWorkflow({ name })` override otherwise). */
|
|
43
68
|
readonly name?: string;
|
|
44
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A function reference a scheduler or workpool may target.
|
|
72
|
+
*
|
|
73
|
+
* `stream` is excluded deliberately, and the exclusion is load-bearing rather
|
|
74
|
+
* than tidiness: a scheduled job is dispatched as an ordinary `/rpc` call, and
|
|
75
|
+
* the function runner cannot execute a stream function (see
|
|
76
|
+
* `create-worker.ts`'s registry note). Accepting one compiles a job that is
|
|
77
|
+
* guaranteed to fail when its alarm fires, long after the call site that
|
|
78
|
+
* scheduled it.
|
|
79
|
+
*/
|
|
80
|
+
type SchedulableReference<Args = unknown, Return = unknown> = FunctionReference<Exclude<FunctionKind, "stream">, Args, Return>;
|
|
45
81
|
/** A cron job's target: either a one-shot function dispatch or a durable workflow start. */
|
|
46
|
-
type CronTarget =
|
|
82
|
+
type CronTarget = SchedulableReference | WorkflowReference;
|
|
47
83
|
/** The arguments a cron's target accepts: a workflow's inferred `params`, else an open record (function args aren't inferred). */
|
|
48
84
|
type CronTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : Record<string, unknown>;
|
|
49
85
|
/**
|
|
50
86
|
* The arguments a one-shot schedule target ({@link Scheduler.runAfter} /
|
|
51
|
-
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it
|
|
52
|
-
* {@link FunctionReference}'s
|
|
53
|
-
* {@link WorkflowReference}'s
|
|
54
|
-
*
|
|
55
|
-
* `params`.
|
|
87
|
+
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it resolves a
|
|
88
|
+
* {@link FunctionReference}'s `args` through {@link ArgsOf} as well as a
|
|
89
|
+
* {@link WorkflowReference}'s `params`, so scheduling a generated function
|
|
90
|
+
* reference is arg-checked against that function's validator while scheduling a
|
|
91
|
+
* workflow/agent is checked against its `params`.
|
|
56
92
|
*/
|
|
57
|
-
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends
|
|
93
|
+
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends SchedulableReference ? ArgsOf<T> : Record<string, unknown>;
|
|
58
94
|
/** Narrow a {@link CronTarget} to a {@link WorkflowReference} by its runtime brand. */
|
|
59
95
|
declare const isWorkflowReference: (target: unknown) => target is WorkflowReference;
|
|
60
96
|
/**
|
|
@@ -172,16 +208,24 @@ interface Scheduler {
|
|
|
172
208
|
* `agents.<name>` ref — which starts a fresh instance on fire (args become
|
|
173
209
|
* its `params`). {@link ScheduleTargetArgs} infers the accepted args from
|
|
174
210
|
* whichever target was passed.
|
|
211
|
+
*
|
|
212
|
+
* **Resolves the job id, a bare string** — the same value `cancel`/`get`
|
|
213
|
+
* take, and the same value the `ctx.scheduler` surface promises. This object
|
|
214
|
+
* IS `ctx.scheduler` on the shard side (codegen installs it behind
|
|
215
|
+
* `SchedulerLike`, whose `runAfter`/`runAt` are declared `Promise<string>`),
|
|
216
|
+
* so resolving a `{ id, scheduledFor }` record here handed mutations an
|
|
217
|
+
* object where every other gate — `@lunora/server`'s `Scheduler`,
|
|
218
|
+
* `@lunora/shard-engine`'s `SchedulerLike`, `@lunora/runtime`'s httpAction
|
|
219
|
+
* ctx, and the docs — said string. Nothing caught it, because the install is
|
|
220
|
+
* a cast: apps wrote the object into a string column and `cancel(id)`
|
|
221
|
+
* answered `{ cancelled: false }` with no error anywhere.
|
|
222
|
+
*
|
|
223
|
+
* The fire instant is not lost: `runAt` was handed it, and a caller that
|
|
224
|
+
* needs it back reads `scheduledFor` off {@link Scheduler.get}.
|
|
175
225
|
*/
|
|
176
|
-
runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}>;
|
|
180
|
-
/** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. */
|
|
181
|
-
runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<{
|
|
182
|
-
id: string;
|
|
183
|
-
scheduledFor: number;
|
|
184
|
-
}>;
|
|
226
|
+
runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
|
|
227
|
+
/** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. Resolves the job id. */
|
|
228
|
+
runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
|
|
185
229
|
}
|
|
186
230
|
/**
|
|
187
231
|
* Cloudflare Durable Object data-residency jurisdiction. Widening union —
|
|
@@ -268,7 +312,7 @@ interface Workpool {
|
|
|
268
312
|
* and the time it was scheduled for (it may not run immediately if the pool
|
|
269
313
|
* is at capacity).
|
|
270
314
|
*/
|
|
271
|
-
enqueue: <F extends
|
|
315
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: EnqueueOptions) => Promise<{
|
|
272
316
|
id: string;
|
|
273
317
|
scheduledFor: number;
|
|
274
318
|
}>;
|
|
@@ -348,7 +392,7 @@ interface QueueWorkpoolOptions {
|
|
|
348
392
|
*/
|
|
349
393
|
interface QueueWorkpool {
|
|
350
394
|
/** Enqueue a single `fn(args)` dispatch. */
|
|
351
|
-
enqueue: <F extends
|
|
395
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: QueueEnqueueOptions) => Promise<void>;
|
|
352
396
|
/** Enqueue many dispatches in one `sendBatch`. Each job names its function `ref`. */
|
|
353
397
|
enqueueBatch: (jobs: ReadonlyArray<{
|
|
354
398
|
args?: Record<string, unknown>;
|
|
@@ -1005,4 +1049,4 @@ declare const warnIfSecondsLeading: (schedule: string, context: string) => void;
|
|
|
1005
1049
|
* {@link warnIfSecondsLeading}.
|
|
1006
1050
|
*/
|
|
1007
1051
|
declare const assertValidCronExpression: (schedule: string, context?: string) => void;
|
|
1008
|
-
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|
|
1052
|
+
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionKind, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"./packem_shared/createScheduler-
|
|
1
|
+
import{default as o}from"./packem_shared/createScheduler-CW8pPy0j.mjs";import{default as a}from"./packem_shared/createWorkpool-d3THj5gc.mjs";import{createCronTrigger as c}from"./packem_shared/createCronTrigger-DSuDZtqj.mjs";import{CRON_SCHEDULE_KINDS as f,compileCronSchedule as l,cronJobs as n}from"./packem_shared/CRON_SCHEDULE_KINDS-xyFk800s.mjs";import{createQueueConsumer as u,createQueueWorkpool as x,httpDispatcher as d}from"./packem_shared/createQueueConsumer-adiyW-4L.mjs";import{MAX_RETRY_ATTEMPTS as S,RETRY_BASE_DELAY_MS as E,SchedulerDO as C}from"./packem_shared/MAX_RETRY_ATTEMPTS-D24I8zY0.mjs";import{createSchedulerHost as h}from"./packem_shared/createSchedulerHost-B-5nnRt8.mjs";import{isWorkflowReference as T}from"./packem_shared/isWorkflowReference-CT3tdefh.mjs";import{assertValidCronExpression as A,isValidCronExpression as g,warnIfSecondsLeading as k}from"./packem_shared/assertValidCronExpression-DnBtukpq.mjs";export{f as CRON_SCHEDULE_KINDS,S as MAX_RETRY_ATTEMPTS,E as RETRY_BASE_DELAY_MS,C as SchedulerDO,A as assertValidCronExpression,l as compileCronSchedule,c as createCronTrigger,u as createQueueConsumer,x as createQueueWorkpool,o as createScheduler,h as createSchedulerHost,a as createWorkpool,n as cronJobs,d as httpDispatcher,g as isValidCronExpression,T as isWorkflowReference,k as warnIfSecondsLeading};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as i}from"@lunora/errors";import{a as y,c as a,g as s}from"./do-client-BKEFA9pM.mjs";import{isWorkflowReference as f}from"./isWorkflowReference-CT3tdefh.mjs";const x=n=>{y(n);const d=async(e,r,t,c={})=>{const u=e instanceof Date?e.getTime():e,o={args:t,instanceName:n.instanceName??"default",maxConcurrency:c.pool===void 0?void 0:c.maxConcurrency,originUrl:n.originUrl,pool:c.pool,retry:c.retry,scheduledFor:u,shardKey:c.shardKey};if(f(r)){if(typeof r.binding!="string"||r.binding.length===0)throw new i("INTERNAL","@lunora/scheduler: workflow/agent schedule target is missing its `binding` — pass the generated `workflows.<name>` / `agents.<name>` reference");return(await a(n,"/schedule",{...o,workflow:r.binding})).id}const l=typeof r=="string"?r:r.__lunoraRef;return(await a(n,"/schedule",{...o,functionPath:l})).id};return{cancel:async e=>a(n,"/cancel",{id:e}),dead:async()=>{const e=await s(n,"/dead");return Array.isArray(e.records)?e.records:[]},deadRetry:async e=>{const{retried:r}=await a(n,"/dead/retry",{id:e});return r===!0},get:async e=>(await s(n,`/get?id=${encodeURIComponent(e)}`)).record??null,list:async()=>{const e=await s(n,"/list");return Array.isArray(e.records)?e.records:[]},runAfter:async(e,r,t,c={})=>{if(!Number.isFinite(e)||e<0)throw new i("INTERNAL","@lunora/scheduler: `delayMs` must be a non-negative finite number");return d(Date.now()+e,r,t,c)},runAt:d}};export{x as default};
|
package/dist/packem_shared/{createSchedulerHost-BnNZ3raF.mjs → createSchedulerHost-B-5nnRt8.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import u from"./createScheduler-CW8pPy0j.mjs";const i=t=>t?.at!==void 0?typeof t.at=="number"?t.at:t.at.getTime():Date.now()+(t?.delayMs??0),m=t=>{const a=u({instanceName:t.instanceName,jurisdiction:t.jurisdiction,namespace:t.namespace,originUrl:t.originUrl}),n=e=>({attempts:e.attempts??0,functionPath:e.functionPath??e.workflow??"",id:e.id,scheduledFor:e.scheduledFor});return{cancel:async e=>{const{cancelled:r}=await a.cancel(e);return r},deadLetter:{list:async()=>(await a.dead()).map(r=>n(r)),requeue:async e=>a.deadRetry(e)},list:async()=>(await a.list()).map(r=>n(r)),schedule:async(e,r,c)=>{const d=a.runAt,s=i(c);return{id:await d(s,e,r,{retry:c?.retry,shardKey:c?.shardKey}),scheduledFor:s}}}};export{m as createSchedulerHost};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/scheduler",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.47",
|
|
4
4
|
"description": "Scheduling for Lunora: runAfter / runAt and Cron Triggers via SchedulerDO",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
50
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
49
|
+
"@lunora/errors": "1.0.0-alpha.27",
|
|
50
|
+
"@lunora/platform": "1.0.0-alpha.23",
|
|
51
51
|
"cron-parser": "5.8.1"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as i}from"@lunora/errors";import{a as y,c,g as s}from"./do-client-BKEFA9pM.mjs";import{isWorkflowReference as f}from"./isWorkflowReference-CT3tdefh.mjs";const D=n=>{y(n);const o=async(e,r,t,a={})=>{const u=e instanceof Date?e.getTime():e,d={args:t,instanceName:n.instanceName??"default",maxConcurrency:a.pool===void 0?void 0:a.maxConcurrency,originUrl:n.originUrl,pool:a.pool,retry:a.retry,scheduledFor:u,shardKey:a.shardKey};if(f(r)){if(typeof r.binding!="string"||r.binding.length===0)throw new i("INTERNAL","@lunora/scheduler: workflow/agent schedule target is missing its `binding` — pass the generated `workflows.<name>` / `agents.<name>` reference");return c(n,"/schedule",{...d,workflow:r.binding})}const l=typeof r=="string"?r:r.__lunoraRef;return c(n,"/schedule",{...d,functionPath:l})};return{cancel:async e=>c(n,"/cancel",{id:e}),dead:async()=>{const e=await s(n,"/dead");return Array.isArray(e.records)?e.records:[]},deadRetry:async e=>{const{retried:r}=await c(n,"/dead/retry",{id:e});return r===!0},get:async e=>(await s(n,`/get?id=${encodeURIComponent(e)}`)).record??null,list:async()=>{const e=await s(n,"/list");return Array.isArray(e.records)?e.records:[]},runAfter:async(e,r,t,a={})=>{if(!Number.isFinite(e)||e<0)throw new i("INTERNAL","@lunora/scheduler: `delayMs` must be a non-negative finite number");return o(Date.now()+e,r,t,a)},runAt:o}};export{D as default};
|