@lunora/scheduler 1.0.0-alpha.13 → 1.0.0-alpha.14
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/dist/index.d.mts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/createScheduler-CsRAEtdb.mjs +1 -0
- package/dist/packem_shared/createSchedulerHost-C5XacwXv.mjs +1 -0
- package/package.json +2 -1
- package/dist/packem_shared/createScheduler-B2YOy_ph.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SchedulerHost } from '@lunora/platform';
|
|
1
2
|
/**
|
|
2
3
|
* Opaque reference to a Lunora function. Mirrors the `FunctionReference` shape
|
|
3
4
|
* emitted by `@lunora/codegen` (and consumed by `@lunora/client`). We avoid a
|
|
@@ -140,6 +141,19 @@ interface Scheduler {
|
|
|
140
141
|
cancel: (id: string) => Promise<{
|
|
141
142
|
cancelled: boolean;
|
|
142
143
|
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Jobs that exhausted their retry budget and were parked under `dead:`
|
|
146
|
+
* (the DO's `/dead` view). Deliberately absent from {@link Scheduler.list} —
|
|
147
|
+
* the park deletes the `id:` header — so this is the only view of a job
|
|
148
|
+
* that failed permanently rather than being silently dropped.
|
|
149
|
+
*/
|
|
150
|
+
dead: () => Promise<ScheduleRecord[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Resurrect a parked job with a fresh attempt budget (the DO's
|
|
153
|
+
* `POST /dead/retry`). `false` when the id is not parked; a racing double
|
|
154
|
+
* recover is a no-op rather than an error.
|
|
155
|
+
*/
|
|
156
|
+
deadRetry: (id: string) => Promise<boolean>;
|
|
143
157
|
/** Resolve a single pending job by id, or `null` when absent (derived from {@link Scheduler.list}). */
|
|
144
158
|
get: (id: string) => Promise<ScheduleRecord | null>;
|
|
145
159
|
/** All pending scheduled jobs (the DO's `/list` view). */
|
|
@@ -842,6 +856,33 @@ declare class SchedulerDO {
|
|
|
842
856
|
private armAlarmIfEarlier;
|
|
843
857
|
private rescheduleAlarm;
|
|
844
858
|
}
|
|
859
|
+
/** What the Cloudflare scheduler host needs from the Worker's environment. */
|
|
860
|
+
interface SchedulerHostOptions {
|
|
861
|
+
/**
|
|
862
|
+
* Named scheduler instance — one `SchedulerDO` per name, useful for tenant
|
|
863
|
+
* isolation. Defaults to `"default"`.
|
|
864
|
+
*/
|
|
865
|
+
instanceName?: string;
|
|
866
|
+
/**
|
|
867
|
+
* Data-residency jurisdiction for the `SchedulerDO`. Pass the same value as
|
|
868
|
+
* the worker's own jurisdiction so scheduled state co-resides with app data.
|
|
869
|
+
*/
|
|
870
|
+
jurisdiction?: "eu" | "fedramp" | "us";
|
|
871
|
+
/** The `SchedulerDO` namespace binding. */
|
|
872
|
+
namespace: Parameters<typeof createScheduler>[0]["namespace"];
|
|
873
|
+
/**
|
|
874
|
+
* Public origin the Worker is mounted at. `SchedulerDO` dispatches back to
|
|
875
|
+
* this base URL when an alarm fires, so a wrong value means jobs fire into
|
|
876
|
+
* nothing.
|
|
877
|
+
*/
|
|
878
|
+
originUrl: string;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Build the Cloudflare {@link SchedulerHost}.
|
|
882
|
+
*
|
|
883
|
+
* The returned host has no `cron` member — see the module docstring.
|
|
884
|
+
*/
|
|
885
|
+
declare const createSchedulerHost: (options: SchedulerHostOptions) => SchedulerHost;
|
|
845
886
|
/** Standard cron expression (5- or 6-field) or a supported `@macro`, per `cron-parser`. */
|
|
846
887
|
declare const isValidCronExpression: (schedule: string) => boolean;
|
|
847
888
|
/**
|
|
@@ -850,4 +891,4 @@ declare const isValidCronExpression: (schedule: string) => boolean;
|
|
|
850
891
|
* job (`cron job "send digest"`) vs. the bare trigger.
|
|
851
892
|
*/
|
|
852
893
|
declare const assertValidCronExpression: (schedule: string, context?: string) => void;
|
|
853
|
-
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 HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference };
|
|
894
|
+
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 HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SchedulerHost } from '@lunora/platform';
|
|
1
2
|
/**
|
|
2
3
|
* Opaque reference to a Lunora function. Mirrors the `FunctionReference` shape
|
|
3
4
|
* emitted by `@lunora/codegen` (and consumed by `@lunora/client`). We avoid a
|
|
@@ -140,6 +141,19 @@ interface Scheduler {
|
|
|
140
141
|
cancel: (id: string) => Promise<{
|
|
141
142
|
cancelled: boolean;
|
|
142
143
|
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Jobs that exhausted their retry budget and were parked under `dead:`
|
|
146
|
+
* (the DO's `/dead` view). Deliberately absent from {@link Scheduler.list} —
|
|
147
|
+
* the park deletes the `id:` header — so this is the only view of a job
|
|
148
|
+
* that failed permanently rather than being silently dropped.
|
|
149
|
+
*/
|
|
150
|
+
dead: () => Promise<ScheduleRecord[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Resurrect a parked job with a fresh attempt budget (the DO's
|
|
153
|
+
* `POST /dead/retry`). `false` when the id is not parked; a racing double
|
|
154
|
+
* recover is a no-op rather than an error.
|
|
155
|
+
*/
|
|
156
|
+
deadRetry: (id: string) => Promise<boolean>;
|
|
143
157
|
/** Resolve a single pending job by id, or `null` when absent (derived from {@link Scheduler.list}). */
|
|
144
158
|
get: (id: string) => Promise<ScheduleRecord | null>;
|
|
145
159
|
/** All pending scheduled jobs (the DO's `/list` view). */
|
|
@@ -842,6 +856,33 @@ declare class SchedulerDO {
|
|
|
842
856
|
private armAlarmIfEarlier;
|
|
843
857
|
private rescheduleAlarm;
|
|
844
858
|
}
|
|
859
|
+
/** What the Cloudflare scheduler host needs from the Worker's environment. */
|
|
860
|
+
interface SchedulerHostOptions {
|
|
861
|
+
/**
|
|
862
|
+
* Named scheduler instance — one `SchedulerDO` per name, useful for tenant
|
|
863
|
+
* isolation. Defaults to `"default"`.
|
|
864
|
+
*/
|
|
865
|
+
instanceName?: string;
|
|
866
|
+
/**
|
|
867
|
+
* Data-residency jurisdiction for the `SchedulerDO`. Pass the same value as
|
|
868
|
+
* the worker's own jurisdiction so scheduled state co-resides with app data.
|
|
869
|
+
*/
|
|
870
|
+
jurisdiction?: "eu" | "fedramp" | "us";
|
|
871
|
+
/** The `SchedulerDO` namespace binding. */
|
|
872
|
+
namespace: Parameters<typeof createScheduler>[0]["namespace"];
|
|
873
|
+
/**
|
|
874
|
+
* Public origin the Worker is mounted at. `SchedulerDO` dispatches back to
|
|
875
|
+
* this base URL when an alarm fires, so a wrong value means jobs fire into
|
|
876
|
+
* nothing.
|
|
877
|
+
*/
|
|
878
|
+
originUrl: string;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Build the Cloudflare {@link SchedulerHost}.
|
|
882
|
+
*
|
|
883
|
+
* The returned host has no `cron` member — see the module docstring.
|
|
884
|
+
*/
|
|
885
|
+
declare const createSchedulerHost: (options: SchedulerHostOptions) => SchedulerHost;
|
|
845
886
|
/** Standard cron expression (5- or 6-field) or a supported `@macro`, per `cron-parser`. */
|
|
846
887
|
declare const isValidCronExpression: (schedule: string) => boolean;
|
|
847
888
|
/**
|
|
@@ -850,4 +891,4 @@ declare const isValidCronExpression: (schedule: string) => boolean;
|
|
|
850
891
|
* job (`cron job "send digest"`) vs. the bare trigger.
|
|
851
892
|
*/
|
|
852
893
|
declare const assertValidCronExpression: (schedule: string, context?: string) => void;
|
|
853
|
-
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 HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference };
|
|
894
|
+
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 HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, 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 };
|
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-CsRAEtdb.mjs";import{default as p}from"./packem_shared/createWorkpool-DyVdhB6o.mjs";import{createCronTrigger as c}from"./packem_shared/createCronTrigger-CyPdVKNF.mjs";import{CRON_SCHEDULE_KINDS as f,compileCronSchedule as l,cronJobs as m}from"./packem_shared/CRON_SCHEDULE_KINDS-CZFw97XW.mjs";import{createQueueConsumer as x,createQueueWorkpool as i,httpDispatcher as n}from"./packem_shared/createQueueConsumer-B0qNXRUJ.mjs";import{SchedulerDO as C}from"./packem_shared/SchedulerDO-DGgeZ-uI.mjs";import{createSchedulerHost as S}from"./packem_shared/createSchedulerHost-C5XacwXv.mjs";import{isWorkflowReference as E}from"./packem_shared/isWorkflowReference-CT3tdefh.mjs";import{assertValidCronExpression as W,isValidCronExpression as g}from"./packem_shared/assertValidCronExpression-DHvO7Vm9.mjs";export{f as CRON_SCHEDULE_KINDS,C as SchedulerDO,W as assertValidCronExpression,l as compileCronSchedule,c as createCronTrigger,x as createQueueConsumer,i as createQueueWorkpool,o as createScheduler,S as createSchedulerHost,p as createWorkpool,m as cronJobs,n as httpDispatcher,g as isValidCronExpression,E as isWorkflowReference};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as i}from"@lunora/errors";import{l as s,u as a}from"./do-client-BFps7NIj.mjs";import{isWorkflowReference as g}from"./isWorkflowReference-CT3tdefh.mjs";const y=n=>{if(!n.namespace)throw new i("INTERNAL","@lunora/scheduler: `namespace` (SchedulerDO binding) is required");if(!n.originUrl)throw new i("INTERNAL","@lunora/scheduler: `originUrl` is required so the DO can dispatch back to the Worker");const c=async(e,r,o,t={})=>{const l=e instanceof Date?e.getTime():e,d={args:o,originUrl:n.originUrl,pool:t.pool,retry:t.retry,scheduledFor:l,shardKey:t.shardKey};if(g(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 a(n,"/schedule",{...d,workflow:r.binding})}const u=typeof r=="string"?r:r.__lunoraRef;return a(n,"/schedule",{...d,functionPath:u})};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,o,t={})=>{if(!Number.isFinite(e)||e<0)throw new i("INTERNAL","@lunora/scheduler: `delayMs` must be a non-negative finite number");return c(Date.now()+e,r,o,t)},runAt:c}};export{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import i from"./createScheduler-CsRAEtdb.mjs";const o=a=>a?.at!==void 0?typeof a.at=="number"?a.at:a.at.getTime():Date.now()+(a?.delayMs??0),u=a=>{const t=i({instanceName:a.instanceName,jurisdiction:a.jurisdiction,namespace:a.namespace,originUrl:a.originUrl}),c=e=>({attempts:e.attempts??0,functionPath:e.functionPath??e.workflow??"",id:e.id,scheduledFor:e.scheduledFor});return{cancel:async e=>{const{cancelled:r}=await t.cancel(e);return r},deadLetter:{list:async()=>(await t.dead()).map(e=>c(e)),requeue:async e=>t.deadRetry(e)},list:async()=>(await t.list()).map(e=>c(e)),schedule:async(e,r,n)=>{const s=t.runAt;return s(o(n),e,r,{retry:n?.retry,shardKey:n?.shardKey})}}};export{u 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.14",
|
|
4
4
|
"description": "Scheduling for Lunora: runAfter / runAt and Cron Triggers via SchedulerDO",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@lunora/errors": "1.0.0-alpha.9",
|
|
50
|
+
"@lunora/platform": "1.0.0-alpha.1",
|
|
50
51
|
"cron-parser": "5.6.2"
|
|
51
52
|
},
|
|
52
53
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as i}from"@lunora/errors";import{l,u as s}from"./do-client-BFps7NIj.mjs";import{isWorkflowReference as g}from"./isWorkflowReference-CT3tdefh.mjs";const m=n=>{if(!n.namespace)throw new i("INTERNAL","@lunora/scheduler: `namespace` (SchedulerDO binding) is required");if(!n.originUrl)throw new i("INTERNAL","@lunora/scheduler: `originUrl` is required so the DO can dispatch back to the Worker");const a=async(e,r,o,t={})=>{const u=e instanceof Date?e.getTime():e,c={args:o,originUrl:n.originUrl,pool:t.pool,retry:t.retry,scheduledFor:u,shardKey:t.shardKey};if(g(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 s(n,"/schedule",{...c,workflow:r.binding})}const d=typeof r=="string"?r:r.__lunoraRef;return s(n,"/schedule",{...c,functionPath:d})};return{cancel:async e=>s(n,"/cancel",{id:e}),get:async e=>(await l(n,`/get?id=${encodeURIComponent(e)}`)).record??null,list:async()=>{const e=await l(n,"/list");return Array.isArray(e.records)?e.records:[]},runAfter:async(e,r,o,t={})=>{if(!Number.isFinite(e)||e<0)throw new i("INTERNAL","@lunora/scheduler: `delayMs` must be a non-negative finite number");return a(Date.now()+e,r,o,t)},runAt:a}};export{m as default};
|