@lssm/lib.jobs 0.0.0-canary-20251206160926
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 +123 -0
- package/dist/contracts/dist/capabilities/openbanking.js +1 -0
- package/dist/contracts/dist/client/index.js +1 -0
- package/dist/contracts/dist/client/react/feature-render.js +1 -0
- package/dist/contracts/dist/client/react/form-render.js +1 -0
- package/dist/contracts/dist/client/react/index.js +1 -0
- package/dist/contracts/dist/events.js +1 -0
- package/dist/contracts/dist/experiments/evaluator.js +1 -0
- package/dist/contracts/dist/graphql-federation/dist/index.js +1 -0
- package/dist/contracts/dist/index.js +1 -0
- package/dist/contracts/dist/install.js +1 -0
- package/dist/contracts/dist/integrations/contracts.js +1 -0
- package/dist/contracts/dist/integrations/index.js +1 -0
- package/dist/contracts/dist/integrations/openbanking/contracts/accounts.js +1 -0
- package/dist/contracts/dist/integrations/openbanking/contracts/balances.js +1 -0
- package/dist/contracts/dist/integrations/openbanking/contracts/index.js +1 -0
- package/dist/contracts/dist/integrations/openbanking/contracts/transactions.js +1 -0
- package/dist/contracts/dist/integrations/openbanking/models.js +1 -0
- package/dist/contracts/dist/integrations/openbanking/telemetry.js +1 -0
- package/dist/contracts/dist/integrations/providers/elevenlabs.js +1 -0
- package/dist/contracts/dist/integrations/providers/gcs-storage.js +1 -0
- package/dist/contracts/dist/integrations/providers/gmail.js +1 -0
- package/dist/contracts/dist/integrations/providers/google-calendar.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/elevenlabs-voice.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/gcs-storage.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/gmail-inbound.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/gmail-outbound.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/google-calendar.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/index.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/mistral-embedding.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/mistral-llm.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/postmark-email.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/powens-client.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/powens-openbanking.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/provider-factory.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/qdrant-vector.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/stripe-payments.js +1 -0
- package/dist/contracts/dist/integrations/providers/impls/twilio-sms.js +1 -0
- package/dist/contracts/dist/integrations/providers/index.js +1 -0
- package/dist/contracts/dist/integrations/providers/mistral.js +1 -0
- package/dist/contracts/dist/integrations/providers/postmark.js +1 -0
- package/dist/contracts/dist/integrations/providers/powens.js +1 -0
- package/dist/contracts/dist/integrations/providers/qdrant.js +1 -0
- package/dist/contracts/dist/integrations/providers/stripe.js +1 -0
- package/dist/contracts/dist/integrations/providers/twilio-sms.js +1 -0
- package/dist/contracts/dist/integrations/runtime.js +1 -0
- package/dist/contracts/dist/integrations/secrets/env-secret-provider.js +1 -0
- package/dist/contracts/dist/integrations/secrets/gcp-secret-manager.js +1 -0
- package/dist/contracts/dist/integrations/secrets/index.js +1 -0
- package/dist/contracts/dist/integrations/secrets/manager.js +1 -0
- package/dist/contracts/dist/integrations/secrets/provider.js +1 -0
- package/dist/contracts/dist/jsonschema.js +1 -0
- package/dist/contracts/dist/knowledge/contracts.js +1 -0
- package/dist/contracts/dist/knowledge/index.js +1 -0
- package/dist/contracts/dist/knowledge/spaces/email-threads.js +1 -0
- package/dist/contracts/dist/knowledge/spaces/financial-docs.js +1 -0
- package/dist/contracts/dist/knowledge/spaces/financial-overview.js +1 -0
- package/dist/contracts/dist/knowledge/spaces/index.js +1 -0
- package/dist/contracts/dist/knowledge/spaces/product-canon.js +1 -0
- package/dist/contracts/dist/knowledge/spaces/support-faq.js +1 -0
- package/dist/contracts/dist/knowledge/spaces/uploaded-docs.js +1 -0
- package/dist/contracts/dist/onboarding-base.js +1 -0
- package/dist/contracts/dist/ownership.js +1 -0
- package/dist/contracts/dist/presentations.js +1 -0
- package/dist/contracts/dist/presentations.v2.js +1 -0
- package/dist/contracts/dist/prompt.js +1 -0
- package/dist/contracts/dist/promptRegistry.js +1 -0
- package/dist/contracts/dist/regenerator/index.js +1 -0
- package/dist/contracts/dist/regenerator/service.js +1 -0
- package/dist/contracts/dist/registry.js +1 -0
- package/dist/contracts/dist/resources.js +1 -0
- package/dist/contracts/dist/schema/dist/EnumType.js +1 -0
- package/dist/contracts/dist/schema/dist/FieldType.js +1 -0
- package/dist/contracts/dist/schema/dist/ScalarTypeEnum.js +1 -0
- package/dist/contracts/dist/schema/dist/SchemaModel.js +1 -0
- package/dist/contracts/dist/schema/dist/entity/defineEntity.js +1 -0
- package/dist/contracts/dist/schema/dist/entity/index.js +1 -0
- package/dist/contracts/dist/schema/dist/entity/types.js +1 -0
- package/dist/contracts/dist/schema/dist/index.js +1 -0
- package/dist/contracts/dist/server/graphql-pothos.js +1 -0
- package/dist/contracts/dist/server/graphql-schema-export.js +1 -0
- package/dist/contracts/dist/server/index.js +1 -0
- package/dist/contracts/dist/server/provider-mcp.js +1 -0
- package/dist/contracts/dist/server/rest-elysia.js +1 -0
- package/dist/contracts/dist/server/rest-express.js +1 -0
- package/dist/contracts/dist/server/rest-generic.js +1 -0
- package/dist/contracts/dist/server/rest-next-app.js +1 -0
- package/dist/contracts/dist/server/rest-next-pages.js +1 -0
- package/dist/contracts/dist/spec.js +1 -0
- package/dist/contracts/dist/telemetry/index.js +1 -0
- package/dist/contracts/dist/telemetry/tracker.js +1 -0
- package/dist/contracts/dist/tests/index.js +1 -0
- package/dist/contracts/dist/tests/runner.js +1 -0
- package/dist/contracts/dist/workflow/index.js +1 -0
- package/dist/contracts/dist/workflow/runner.js +1 -0
- package/dist/contracts/index.d.ts +546 -0
- package/dist/contracts/index.js +1 -0
- package/dist/entities/index.d.ts +144 -0
- package/dist/entities/index.js +1 -0
- package/dist/events.d.ts +387 -0
- package/dist/events.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -0
- package/dist/queue/index.d.ts +3 -0
- package/dist/queue/index.js +1 -0
- package/dist/queue/memory-queue.d.ts +34 -0
- package/dist/queue/memory-queue.js +1 -0
- package/dist/queue/types.d.ts +131 -0
- package/dist/queue/types.js +1 -0
- package/dist/scheduler/index.d.ts +92 -0
- package/dist/scheduler/index.js +1 -0
- package/dist/schema/dist/EnumType.js +1 -0
- package/dist/schema/dist/FieldType.js +1 -0
- package/dist/schema/dist/ScalarTypeEnum.js +1 -0
- package/dist/schema/dist/SchemaModel.js +1 -0
- package/dist/schema/dist/entity/defineEntity.js +1 -0
- package/dist/schema/dist/entity/index.js +1 -0
- package/dist/schema/dist/entity/types.js +1 -0
- package/dist/schema/dist/index.js +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"../schema/dist/entity/defineEntity.js";import"../schema/dist/index.js";const i=t({name:`JobStatus`,values:[`PENDING`,`RUNNING`,`COMPLETED`,`FAILED`,`CANCELLED`,`DEAD_LETTER`],schema:`lssm_jobs`,description:`Status of a background job.`}),a=r({name:`Job`,description:`A background job for async processing.`,schema:`lssm_jobs`,map:`job`,fields:{id:n.id({description:`Unique job identifier`}),type:n.string({description:`Job type identifier`}),version:n.int({default:1,description:`Job type version`}),payload:n.json({description:`Job payload data`}),status:n.enum(`JobStatus`,{default:`PENDING`}),priority:n.int({default:0,description:`Higher = more urgent`}),attempts:n.int({default:0,description:`Number of execution attempts`}),maxRetries:n.int({default:3,description:`Maximum retry attempts`}),lastError:n.string({isOptional:!0,description:`Last error message`}),lastErrorStack:n.string({isOptional:!0,description:`Last error stack trace`}),scheduledAt:n.dateTime({isOptional:!0,description:`When job should be processed`}),startedAt:n.dateTime({isOptional:!0,description:`When processing started`}),completedAt:n.dateTime({isOptional:!0,description:`When processing completed`}),timeoutAt:n.dateTime({isOptional:!0,description:`Job timeout deadline`}),dedupeKey:n.string({isOptional:!0,description:`Key for deduplication`}),tenantId:n.string({isOptional:!0,description:`Tenant/org context`}),userId:n.string({isOptional:!0,description:`User who enqueued`}),traceId:n.string({isOptional:!0,description:`Distributed trace ID`}),metadata:n.json({isOptional:!0,description:`Additional metadata`}),result:n.json({isOptional:!0,description:`Job result data`}),createdAt:n.createdAt(),updatedAt:n.updatedAt(),scheduledJob:n.belongsTo(`ScheduledJob`,[`scheduledJobId`],[`id`]),scheduledJobId:n.string({isOptional:!0}),executions:n.hasMany(`JobExecution`)},indexes:[e.on([`status`,`scheduledAt`]),e.on([`type`,`status`]),e.on([`tenantId`,`status`]),e.unique([`dedupeKey`],{name:`job_dedupe_key_unique`})],enums:[i]}),o=r({name:`ScheduledJob`,description:`A scheduled/recurring job definition.`,schema:`lssm_jobs`,map:`scheduled_job`,fields:{id:n.id(),name:n.string({isUnique:!0,description:`Unique schedule name`}),description:n.string({isOptional:!0}),cronExpression:n.string({description:`Cron expression for scheduling`}),timezone:n.string({default:`"UTC"`,description:`Timezone for cron evaluation`}),jobType:n.string({description:`Job type to create`}),jobVersion:n.int({default:1}),payload:n.json({isOptional:!0,description:`Default payload for created jobs`}),maxRetries:n.int({default:3}),timeoutMs:n.int({isOptional:!0,description:`Job timeout in milliseconds`}),enabled:n.boolean({default:!0}),lastRunAt:n.dateTime({isOptional:!0}),nextRunAt:n.dateTime({isOptional:!0}),tenantId:n.string({isOptional:!0}),createdAt:n.createdAt(),updatedAt:n.updatedAt(),jobs:n.hasMany(`Job`)},indexes:[e.on([`enabled`,`nextRunAt`])]}),s=r({name:`JobExecution`,description:`A single execution attempt of a job.`,schema:`lssm_jobs`,map:`job_execution`,fields:{id:n.id(),jobId:n.foreignKey(),attemptNumber:n.int({description:`Which attempt this is`}),startedAt:n.dateTime(),completedAt:n.dateTime({isOptional:!0}),durationMs:n.int({isOptional:!0}),success:n.boolean({isOptional:!0}),error:n.string({isOptional:!0}),errorStack:n.string({isOptional:!0}),result:n.json({isOptional:!0}),workerId:n.string({isOptional:!0,description:`ID of worker that processed`}),job:n.belongsTo(`Job`,[`jobId`],[`id`],{onDelete:`Cascade`})},indexes:[e.on([`jobId`,`attemptNumber`])]}),c=[a,o,s],l={moduleId:`@lssm/lib.jobs`,entities:c,enums:[i]};export{a as JobEntity,s as JobExecutionEntity,i as JobStatusEnum,o as ScheduledJobEntity,c as jobEntities,l as jobsSchemaContribution};
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import * as _lssm_lib_schema114 from "@lssm/lib.schema";
|
|
2
|
+
import * as _lssm_lib_contracts0 from "@lssm/lib.contracts";
|
|
3
|
+
|
|
4
|
+
//#region src/events.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Emitted when a job is enqueued.
|
|
7
|
+
*/
|
|
8
|
+
declare const JobEnqueuedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
9
|
+
jobId: {
|
|
10
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
11
|
+
isOptional: false;
|
|
12
|
+
};
|
|
13
|
+
type: {
|
|
14
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
15
|
+
isOptional: false;
|
|
16
|
+
};
|
|
17
|
+
priority: {
|
|
18
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
19
|
+
isOptional: false;
|
|
20
|
+
};
|
|
21
|
+
scheduledAt: {
|
|
22
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
23
|
+
isOptional: true;
|
|
24
|
+
};
|
|
25
|
+
tenantId: {
|
|
26
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
27
|
+
isOptional: true;
|
|
28
|
+
};
|
|
29
|
+
enqueuedAt: {
|
|
30
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
31
|
+
isOptional: false;
|
|
32
|
+
};
|
|
33
|
+
}>>;
|
|
34
|
+
/**
|
|
35
|
+
* Emitted when a job starts processing.
|
|
36
|
+
*/
|
|
37
|
+
declare const JobStartedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
38
|
+
jobId: {
|
|
39
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
40
|
+
isOptional: false;
|
|
41
|
+
};
|
|
42
|
+
type: {
|
|
43
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
44
|
+
isOptional: false;
|
|
45
|
+
};
|
|
46
|
+
attempt: {
|
|
47
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
48
|
+
isOptional: false;
|
|
49
|
+
};
|
|
50
|
+
startedAt: {
|
|
51
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
52
|
+
isOptional: false;
|
|
53
|
+
};
|
|
54
|
+
}>>;
|
|
55
|
+
/**
|
|
56
|
+
* Emitted when a job completes successfully.
|
|
57
|
+
*/
|
|
58
|
+
declare const JobCompletedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
59
|
+
jobId: {
|
|
60
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
61
|
+
isOptional: false;
|
|
62
|
+
};
|
|
63
|
+
type: {
|
|
64
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
65
|
+
isOptional: false;
|
|
66
|
+
};
|
|
67
|
+
attempt: {
|
|
68
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
69
|
+
isOptional: false;
|
|
70
|
+
};
|
|
71
|
+
durationMs: {
|
|
72
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
73
|
+
isOptional: false;
|
|
74
|
+
};
|
|
75
|
+
completedAt: {
|
|
76
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
77
|
+
isOptional: false;
|
|
78
|
+
};
|
|
79
|
+
}>>;
|
|
80
|
+
/**
|
|
81
|
+
* Emitted when a job fails (single attempt).
|
|
82
|
+
*/
|
|
83
|
+
declare const JobFailedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
84
|
+
jobId: {
|
|
85
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
86
|
+
isOptional: false;
|
|
87
|
+
};
|
|
88
|
+
type: {
|
|
89
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
90
|
+
isOptional: false;
|
|
91
|
+
};
|
|
92
|
+
attempt: {
|
|
93
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
94
|
+
isOptional: false;
|
|
95
|
+
};
|
|
96
|
+
error: {
|
|
97
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
98
|
+
isOptional: false;
|
|
99
|
+
};
|
|
100
|
+
willRetry: {
|
|
101
|
+
type: _lssm_lib_schema114.FieldType<boolean, boolean>;
|
|
102
|
+
isOptional: false;
|
|
103
|
+
};
|
|
104
|
+
failedAt: {
|
|
105
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
106
|
+
isOptional: false;
|
|
107
|
+
};
|
|
108
|
+
}>>;
|
|
109
|
+
/**
|
|
110
|
+
* Emitted when a job is being retried.
|
|
111
|
+
*/
|
|
112
|
+
declare const JobRetryingEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
113
|
+
jobId: {
|
|
114
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
115
|
+
isOptional: false;
|
|
116
|
+
};
|
|
117
|
+
type: {
|
|
118
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
119
|
+
isOptional: false;
|
|
120
|
+
};
|
|
121
|
+
attempt: {
|
|
122
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
123
|
+
isOptional: false;
|
|
124
|
+
};
|
|
125
|
+
nextAttemptAt: {
|
|
126
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
127
|
+
isOptional: false;
|
|
128
|
+
};
|
|
129
|
+
backoffMs: {
|
|
130
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
131
|
+
isOptional: false;
|
|
132
|
+
};
|
|
133
|
+
}>>;
|
|
134
|
+
/**
|
|
135
|
+
* Emitted when a job is moved to dead letter queue.
|
|
136
|
+
*/
|
|
137
|
+
declare const JobDeadLetteredEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
138
|
+
jobId: {
|
|
139
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
140
|
+
isOptional: false;
|
|
141
|
+
};
|
|
142
|
+
type: {
|
|
143
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
144
|
+
isOptional: false;
|
|
145
|
+
};
|
|
146
|
+
attempts: {
|
|
147
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
148
|
+
isOptional: false;
|
|
149
|
+
};
|
|
150
|
+
lastError: {
|
|
151
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
152
|
+
isOptional: false;
|
|
153
|
+
};
|
|
154
|
+
deadLetteredAt: {
|
|
155
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
156
|
+
isOptional: false;
|
|
157
|
+
};
|
|
158
|
+
}>>;
|
|
159
|
+
/**
|
|
160
|
+
* Emitted when a job is cancelled.
|
|
161
|
+
*/
|
|
162
|
+
declare const JobCancelledEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
163
|
+
jobId: {
|
|
164
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
165
|
+
isOptional: false;
|
|
166
|
+
};
|
|
167
|
+
type: {
|
|
168
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
169
|
+
isOptional: false;
|
|
170
|
+
};
|
|
171
|
+
cancelledBy: {
|
|
172
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
173
|
+
isOptional: true;
|
|
174
|
+
};
|
|
175
|
+
cancelledAt: {
|
|
176
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
177
|
+
isOptional: false;
|
|
178
|
+
};
|
|
179
|
+
}>>;
|
|
180
|
+
/**
|
|
181
|
+
* Emitted when a scheduled job is triggered.
|
|
182
|
+
*/
|
|
183
|
+
declare const ScheduledJobTriggeredEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
184
|
+
scheduleName: {
|
|
185
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
186
|
+
isOptional: false;
|
|
187
|
+
};
|
|
188
|
+
jobId: {
|
|
189
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
190
|
+
isOptional: false;
|
|
191
|
+
};
|
|
192
|
+
jobType: {
|
|
193
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
194
|
+
isOptional: false;
|
|
195
|
+
};
|
|
196
|
+
triggeredAt: {
|
|
197
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
198
|
+
isOptional: false;
|
|
199
|
+
};
|
|
200
|
+
nextRunAt: {
|
|
201
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
202
|
+
isOptional: true;
|
|
203
|
+
};
|
|
204
|
+
}>>;
|
|
205
|
+
/**
|
|
206
|
+
* All job events.
|
|
207
|
+
*/
|
|
208
|
+
declare const JobEvents: {
|
|
209
|
+
JobEnqueuedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
210
|
+
jobId: {
|
|
211
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
212
|
+
isOptional: false;
|
|
213
|
+
};
|
|
214
|
+
type: {
|
|
215
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
216
|
+
isOptional: false;
|
|
217
|
+
};
|
|
218
|
+
priority: {
|
|
219
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
220
|
+
isOptional: false;
|
|
221
|
+
};
|
|
222
|
+
scheduledAt: {
|
|
223
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
224
|
+
isOptional: true;
|
|
225
|
+
};
|
|
226
|
+
tenantId: {
|
|
227
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
228
|
+
isOptional: true;
|
|
229
|
+
};
|
|
230
|
+
enqueuedAt: {
|
|
231
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
232
|
+
isOptional: false;
|
|
233
|
+
};
|
|
234
|
+
}>>;
|
|
235
|
+
JobStartedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
236
|
+
jobId: {
|
|
237
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
238
|
+
isOptional: false;
|
|
239
|
+
};
|
|
240
|
+
type: {
|
|
241
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
242
|
+
isOptional: false;
|
|
243
|
+
};
|
|
244
|
+
attempt: {
|
|
245
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
246
|
+
isOptional: false;
|
|
247
|
+
};
|
|
248
|
+
startedAt: {
|
|
249
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
250
|
+
isOptional: false;
|
|
251
|
+
};
|
|
252
|
+
}>>;
|
|
253
|
+
JobCompletedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
254
|
+
jobId: {
|
|
255
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
256
|
+
isOptional: false;
|
|
257
|
+
};
|
|
258
|
+
type: {
|
|
259
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
260
|
+
isOptional: false;
|
|
261
|
+
};
|
|
262
|
+
attempt: {
|
|
263
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
264
|
+
isOptional: false;
|
|
265
|
+
};
|
|
266
|
+
durationMs: {
|
|
267
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
268
|
+
isOptional: false;
|
|
269
|
+
};
|
|
270
|
+
completedAt: {
|
|
271
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
272
|
+
isOptional: false;
|
|
273
|
+
};
|
|
274
|
+
}>>;
|
|
275
|
+
JobFailedEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
276
|
+
jobId: {
|
|
277
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
278
|
+
isOptional: false;
|
|
279
|
+
};
|
|
280
|
+
type: {
|
|
281
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
282
|
+
isOptional: false;
|
|
283
|
+
};
|
|
284
|
+
attempt: {
|
|
285
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
286
|
+
isOptional: false;
|
|
287
|
+
};
|
|
288
|
+
error: {
|
|
289
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
290
|
+
isOptional: false;
|
|
291
|
+
};
|
|
292
|
+
willRetry: {
|
|
293
|
+
type: _lssm_lib_schema114.FieldType<boolean, boolean>;
|
|
294
|
+
isOptional: false;
|
|
295
|
+
};
|
|
296
|
+
failedAt: {
|
|
297
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
298
|
+
isOptional: false;
|
|
299
|
+
};
|
|
300
|
+
}>>;
|
|
301
|
+
JobRetryingEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
302
|
+
jobId: {
|
|
303
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
304
|
+
isOptional: false;
|
|
305
|
+
};
|
|
306
|
+
type: {
|
|
307
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
308
|
+
isOptional: false;
|
|
309
|
+
};
|
|
310
|
+
attempt: {
|
|
311
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
312
|
+
isOptional: false;
|
|
313
|
+
};
|
|
314
|
+
nextAttemptAt: {
|
|
315
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
316
|
+
isOptional: false;
|
|
317
|
+
};
|
|
318
|
+
backoffMs: {
|
|
319
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
320
|
+
isOptional: false;
|
|
321
|
+
};
|
|
322
|
+
}>>;
|
|
323
|
+
JobDeadLetteredEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
324
|
+
jobId: {
|
|
325
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
326
|
+
isOptional: false;
|
|
327
|
+
};
|
|
328
|
+
type: {
|
|
329
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
330
|
+
isOptional: false;
|
|
331
|
+
};
|
|
332
|
+
attempts: {
|
|
333
|
+
type: _lssm_lib_schema114.FieldType<number, number>;
|
|
334
|
+
isOptional: false;
|
|
335
|
+
};
|
|
336
|
+
lastError: {
|
|
337
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
338
|
+
isOptional: false;
|
|
339
|
+
};
|
|
340
|
+
deadLetteredAt: {
|
|
341
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
342
|
+
isOptional: false;
|
|
343
|
+
};
|
|
344
|
+
}>>;
|
|
345
|
+
JobCancelledEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
346
|
+
jobId: {
|
|
347
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
348
|
+
isOptional: false;
|
|
349
|
+
};
|
|
350
|
+
type: {
|
|
351
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
352
|
+
isOptional: false;
|
|
353
|
+
};
|
|
354
|
+
cancelledBy: {
|
|
355
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
356
|
+
isOptional: true;
|
|
357
|
+
};
|
|
358
|
+
cancelledAt: {
|
|
359
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
360
|
+
isOptional: false;
|
|
361
|
+
};
|
|
362
|
+
}>>;
|
|
363
|
+
ScheduledJobTriggeredEvent: _lssm_lib_contracts0.EventSpec<_lssm_lib_schema114.SchemaModel<{
|
|
364
|
+
scheduleName: {
|
|
365
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
366
|
+
isOptional: false;
|
|
367
|
+
};
|
|
368
|
+
jobId: {
|
|
369
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
370
|
+
isOptional: false;
|
|
371
|
+
};
|
|
372
|
+
jobType: {
|
|
373
|
+
type: _lssm_lib_schema114.FieldType<string, string>;
|
|
374
|
+
isOptional: false;
|
|
375
|
+
};
|
|
376
|
+
triggeredAt: {
|
|
377
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
378
|
+
isOptional: false;
|
|
379
|
+
};
|
|
380
|
+
nextRunAt: {
|
|
381
|
+
type: _lssm_lib_schema114.FieldType<Date, string>;
|
|
382
|
+
isOptional: true;
|
|
383
|
+
};
|
|
384
|
+
}>>;
|
|
385
|
+
};
|
|
386
|
+
//#endregion
|
|
387
|
+
export { JobCancelledEvent, JobCompletedEvent, JobDeadLetteredEvent, JobEnqueuedEvent, JobEvents, JobFailedEvent, JobRetryingEvent, JobStartedEvent, ScheduledJobTriggeredEvent };
|
package/dist/events.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{l as e}from"./schema/dist/ScalarTypeEnum.js";import{n as t}from"./schema/dist/SchemaModel.js";import"./schema/dist/index.js";import{e as n}from"./contracts/dist/events.js";import"./contracts/dist/index.js";const r=t({name:`JobEnqueuedEventPayload`,description:`Payload when a job is added to the queue`,fields:{jobId:{type:e.String_unsecure(),isOptional:!1},type:{type:e.String_unsecure(),isOptional:!1},priority:{type:e.Int_unsecure(),isOptional:!1},scheduledAt:{type:e.DateTime(),isOptional:!0},tenantId:{type:e.String_unsecure(),isOptional:!0},enqueuedAt:{type:e.DateTime(),isOptional:!1}}}),i=t({name:`JobStartedEventPayload`,description:`Payload when a job starts processing`,fields:{jobId:{type:e.String_unsecure(),isOptional:!1},type:{type:e.String_unsecure(),isOptional:!1},attempt:{type:e.Int_unsecure(),isOptional:!1},startedAt:{type:e.DateTime(),isOptional:!1}}}),a=t({name:`JobCompletedEventPayload`,description:`Payload when a job completes successfully`,fields:{jobId:{type:e.String_unsecure(),isOptional:!1},type:{type:e.String_unsecure(),isOptional:!1},attempt:{type:e.Int_unsecure(),isOptional:!1},durationMs:{type:e.Int_unsecure(),isOptional:!1},completedAt:{type:e.DateTime(),isOptional:!1}}}),o=t({name:`JobFailedEventPayload`,description:`Payload when a job attempt fails`,fields:{jobId:{type:e.String_unsecure(),isOptional:!1},type:{type:e.String_unsecure(),isOptional:!1},attempt:{type:e.Int_unsecure(),isOptional:!1},error:{type:e.String_unsecure(),isOptional:!1},willRetry:{type:e.Boolean(),isOptional:!1},failedAt:{type:e.DateTime(),isOptional:!1}}}),s=t({name:`JobRetryingEventPayload`,description:`Payload when a job is scheduled for retry`,fields:{jobId:{type:e.String_unsecure(),isOptional:!1},type:{type:e.String_unsecure(),isOptional:!1},attempt:{type:e.Int_unsecure(),isOptional:!1},nextAttemptAt:{type:e.DateTime(),isOptional:!1},backoffMs:{type:e.Int_unsecure(),isOptional:!1}}}),c=t({name:`JobDeadLetteredEventPayload`,description:`Payload when a job is moved to dead letter queue`,fields:{jobId:{type:e.String_unsecure(),isOptional:!1},type:{type:e.String_unsecure(),isOptional:!1},attempts:{type:e.Int_unsecure(),isOptional:!1},lastError:{type:e.String_unsecure(),isOptional:!1},deadLetteredAt:{type:e.DateTime(),isOptional:!1}}}),l=t({name:`JobCancelledEventPayload`,description:`Payload when a job is cancelled`,fields:{jobId:{type:e.String_unsecure(),isOptional:!1},type:{type:e.String_unsecure(),isOptional:!1},cancelledBy:{type:e.String_unsecure(),isOptional:!0},cancelledAt:{type:e.DateTime(),isOptional:!1}}}),u=t({name:`ScheduledJobTriggeredEventPayload`,description:`Payload when a scheduled job is triggered`,fields:{scheduleName:{type:e.String_unsecure(),isOptional:!1},jobId:{type:e.String_unsecure(),isOptional:!1},jobType:{type:e.String_unsecure(),isOptional:!1},triggeredAt:{type:e.DateTime(),isOptional:!1},nextRunAt:{type:e.DateTime(),isOptional:!0}}}),d=n({name:`job.enqueued`,version:1,description:`A job has been added to the queue.`,payload:r}),f=n({name:`job.started`,version:1,description:`A job has started processing.`,payload:i}),p=n({name:`job.completed`,version:1,description:`A job has completed successfully.`,payload:a}),m=n({name:`job.failed`,version:1,description:`A job attempt has failed.`,payload:o}),h=n({name:`job.retrying`,version:1,description:`A job is being scheduled for retry.`,payload:s}),g=n({name:`job.dead_lettered`,version:1,description:`A job has exhausted all retries and moved to dead letter queue.`,payload:c}),_=n({name:`job.cancelled`,version:1,description:`A job has been cancelled.`,payload:l}),v=n({name:`scheduler.job_triggered`,version:1,description:`A scheduled job has been triggered.`,payload:u}),y={JobEnqueuedEvent:d,JobStartedEvent:f,JobCompletedEvent:p,JobFailedEvent:m,JobRetryingEvent:h,JobDeadLetteredEvent:g,JobCancelledEvent:_,ScheduledJobTriggeredEvent:v};export{_ as JobCancelledEvent,p as JobCompletedEvent,g as JobDeadLetteredEvent,d as JobEnqueuedEvent,y as JobEvents,m as JobFailedEvent,h as JobRetryingEvent,f as JobStartedEvent,v as ScheduledJobTriggeredEvent};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CancelJobContract, CreateScheduledJobContract, EnqueueJobContract, GetJobContract, GetQueueStatsContract, JobModel, ListScheduledJobsContract, QueueStatsModel, ScheduledJobModel, ToggleScheduledJobContract } from "./contracts/index.js";
|
|
2
|
+
import { JobEntity, JobExecutionEntity, JobStatusEnum, ScheduledJobEntity, jobEntities, jobsSchemaContribution } from "./entities/index.js";
|
|
3
|
+
import { JobCancelledEvent, JobCompletedEvent, JobDeadLetteredEvent, JobEnqueuedEvent, JobEvents, JobFailedEvent, JobRetryingEvent, JobStartedEvent, ScheduledJobTriggeredEvent } from "./events.js";
|
|
4
|
+
import { DEFAULT_RETRY_POLICY, EnqueueOptions, Job, JobHandler, JobQueue, JobStatus, JobTypeDef, QueueStats, RetryPolicy, calculateBackoff, defineJobType } from "./queue/types.js";
|
|
5
|
+
import { MemoryJobQueue, MemoryQueueOptions } from "./queue/memory-queue.js";
|
|
6
|
+
import "./queue/index.js";
|
|
7
|
+
import { ActiveSchedule, JobScheduler, ScheduledJobConfig, createScheduler, defineSchedule } from "./scheduler/index.js";
|
|
8
|
+
export { ActiveSchedule, CancelJobContract, CreateScheduledJobContract, DEFAULT_RETRY_POLICY, EnqueueJobContract, EnqueueOptions, GetJobContract, GetQueueStatsContract, Job, JobCancelledEvent, JobCompletedEvent, JobDeadLetteredEvent, JobEnqueuedEvent, JobEntity, JobEvents, JobExecutionEntity, JobFailedEvent, JobHandler, JobModel, JobQueue, JobRetryingEvent, JobScheduler, JobStartedEvent, JobStatus, JobStatusEnum, JobTypeDef, ListScheduledJobsContract, MemoryJobQueue, MemoryQueueOptions, QueueStats, QueueStatsModel, RetryPolicy, ScheduledJobConfig, ScheduledJobEntity, ScheduledJobModel, ScheduledJobTriggeredEvent, ToggleScheduledJobContract, calculateBackoff, createScheduler, defineJobType, defineSchedule, jobEntities, jobsSchemaContribution };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{JobCancelledEvent as e,JobCompletedEvent as t,JobDeadLetteredEvent as n,JobEnqueuedEvent as r,JobEvents as i,JobFailedEvent as a,JobRetryingEvent as o,JobStartedEvent as s,ScheduledJobTriggeredEvent as c}from"./events.js";import{JobEntity as l,JobExecutionEntity as u,JobStatusEnum as d,ScheduledJobEntity as f,jobEntities as p,jobsSchemaContribution as m}from"./entities/index.js";import{DEFAULT_RETRY_POLICY as h,calculateBackoff as g,defineJobType as _}from"./queue/types.js";import{MemoryJobQueue as v}from"./queue/memory-queue.js";import"./queue/index.js";import{JobScheduler as y,createScheduler as b,defineSchedule as x}from"./scheduler/index.js";import{CancelJobContract as S,CreateScheduledJobContract as C,EnqueueJobContract as w,GetJobContract as T,GetQueueStatsContract as E,JobModel as D,ListScheduledJobsContract as O,QueueStatsModel as k,ScheduledJobModel as A,ToggleScheduledJobContract as j}from"./contracts/index.js";export{S as CancelJobContract,C as CreateScheduledJobContract,h as DEFAULT_RETRY_POLICY,w as EnqueueJobContract,T as GetJobContract,E as GetQueueStatsContract,e as JobCancelledEvent,t as JobCompletedEvent,n as JobDeadLetteredEvent,r as JobEnqueuedEvent,l as JobEntity,i as JobEvents,u as JobExecutionEntity,a as JobFailedEvent,D as JobModel,o as JobRetryingEvent,y as JobScheduler,s as JobStartedEvent,d as JobStatusEnum,O as ListScheduledJobsContract,v as MemoryJobQueue,k as QueueStatsModel,f as ScheduledJobEntity,A as ScheduledJobModel,c as ScheduledJobTriggeredEvent,j as ToggleScheduledJobContract,g as calculateBackoff,b as createScheduler,_ as defineJobType,x as defineSchedule,p as jobEntities,m as jobsSchemaContribution};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DEFAULT_RETRY_POLICY, EnqueueOptions, Job, JobHandler, JobQueue, JobStatus, JobTypeDef, QueueStats, RetryPolicy, calculateBackoff, defineJobType } from "./types.js";
|
|
2
|
+
import { MemoryJobQueue, MemoryQueueOptions } from "./memory-queue.js";
|
|
3
|
+
export { DEFAULT_RETRY_POLICY, EnqueueOptions, Job, JobHandler, JobQueue, JobStatus, JobTypeDef, MemoryJobQueue, MemoryQueueOptions, QueueStats, RetryPolicy, calculateBackoff, defineJobType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DEFAULT_RETRY_POLICY as e,calculateBackoff as t,defineJobType as n}from"./types.js";import{MemoryJobQueue as r}from"./memory-queue.js";export{e as DEFAULT_RETRY_POLICY,r as MemoryJobQueue,t as calculateBackoff,n as defineJobType};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EnqueueOptions, Job, JobHandler, JobQueue, QueueStats, RetryPolicy } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/queue/memory-queue.d.ts
|
|
4
|
+
interface MemoryQueueOptions {
|
|
5
|
+
/** Poll interval in milliseconds */
|
|
6
|
+
pollIntervalMs?: number;
|
|
7
|
+
/** Maximum concurrent jobs */
|
|
8
|
+
concurrency?: number;
|
|
9
|
+
/** Default retry policy */
|
|
10
|
+
retryPolicy?: RetryPolicy;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* In-memory job queue for development and testing.
|
|
14
|
+
*/
|
|
15
|
+
declare class MemoryJobQueue implements JobQueue {
|
|
16
|
+
private readonly jobs;
|
|
17
|
+
private readonly handlers;
|
|
18
|
+
private timer?;
|
|
19
|
+
private activeCount;
|
|
20
|
+
private readonly pollIntervalMs;
|
|
21
|
+
private readonly concurrency;
|
|
22
|
+
private readonly retryPolicy;
|
|
23
|
+
constructor(options?: MemoryQueueOptions);
|
|
24
|
+
enqueue<TPayload>(jobType: string, payload: TPayload, options?: EnqueueOptions): Promise<Job<TPayload>>;
|
|
25
|
+
register<TPayload, TResult = void>(jobType: string, handler: JobHandler<TPayload, TResult>): void;
|
|
26
|
+
start(): void;
|
|
27
|
+
stop(): Promise<void>;
|
|
28
|
+
getJob(jobId: string): Promise<Job | null>;
|
|
29
|
+
cancelJob(jobId: string): Promise<boolean>;
|
|
30
|
+
getStats(): Promise<QueueStats>;
|
|
31
|
+
private processNext;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { MemoryJobQueue, MemoryQueueOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DEFAULT_RETRY_POLICY as e,calculateBackoff as t}from"./types.js";import{randomUUID as n}from"node:crypto";var r=class{jobs=new Map;handlers=new Map;timer;activeCount=0;pollIntervalMs;concurrency;retryPolicy;constructor(t={}){this.pollIntervalMs=t.pollIntervalMs??200,this.concurrency=t.concurrency??5,this.retryPolicy=t.retryPolicy??e}async enqueue(e,t,r={}){if(r.dedupeKey){let e=Array.from(this.jobs.values()).find(e=>e.dedupeKey===r.dedupeKey&&e.status===`pending`);if(e)return e}let i=new Date,a=r.delaySeconds?new Date(i.getTime()+r.delaySeconds*1e3):i,o={id:n(),type:e,version:1,payload:t,status:`pending`,priority:r.priority??0,attempts:0,maxRetries:r.maxRetries??this.retryPolicy.maxRetries,createdAt:i,updatedAt:i,scheduledAt:a,dedupeKey:r.dedupeKey,tenantId:r.tenantId,userId:r.userId,traceId:r.traceId,metadata:r.metadata};return r.timeoutMs&&(o.timeoutAt=new Date(i.getTime()+r.timeoutMs)),this.jobs.set(o.id,o),o}register(e,t){this.handlers.set(e,t)}start(){this.timer||=setInterval(()=>{this.processNext()},this.pollIntervalMs)}async stop(){for(this.timer&&=(clearInterval(this.timer),void 0);this.activeCount>0;)await new Promise(e=>setTimeout(e,50))}async getJob(e){return this.jobs.get(e)??null}async cancelJob(e){let t=this.jobs.get(e);return!t||t.status!==`pending`?!1:(t.status=`cancelled`,t.updatedAt=new Date,!0)}async getStats(){let e={pending:0,running:0,completed:0,failed:0,deadLetter:0};for(let t of this.jobs.values())switch(t.status){case`pending`:e.pending++;break;case`running`:e.running++;break;case`completed`:e.completed++;break;case`failed`:e.failed++;break;case`dead_letter`:e.deadLetter++;break}return e}async processNext(){if(this.activeCount>=this.concurrency)return;let e=new Date,n=Array.from(this.jobs.values()).filter(t=>t.status===`pending`&&(!t.scheduledAt||t.scheduledAt<=e)).sort((e,t)=>e.priority===t.priority?(e.scheduledAt?.getTime()??0)-(t.scheduledAt?.getTime()??0):t.priority-e.priority)[0];if(!n)return;let r=this.handlers.get(n.type);if(r){this.activeCount++,n.status=`running`,n.startedAt=new Date,n.updatedAt=new Date,n.attempts+=1;try{let e=await r(n);n.status=`completed`,n.completedAt=new Date,n.result=e}catch(e){if(n.lastError=e instanceof Error?e.message:`Unknown error`,n.attempts>=n.maxRetries)n.status=`dead_letter`;else{let e=t(n.attempts,this.retryPolicy);n.status=`pending`,n.scheduledAt=new Date(Date.now()+e)}}finally{n.updatedAt=new Date,this.activeCount--}}}};export{r as MemoryJobQueue};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/queue/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Job status values.
|
|
7
|
+
*/
|
|
8
|
+
type JobStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | 'dead_letter';
|
|
9
|
+
/**
|
|
10
|
+
* A job in the queue.
|
|
11
|
+
*/
|
|
12
|
+
interface Job<TPayload = unknown> {
|
|
13
|
+
id: string;
|
|
14
|
+
type: string;
|
|
15
|
+
version: number;
|
|
16
|
+
payload: TPayload;
|
|
17
|
+
status: JobStatus;
|
|
18
|
+
priority: number;
|
|
19
|
+
attempts: number;
|
|
20
|
+
maxRetries: number;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
scheduledAt?: Date;
|
|
24
|
+
startedAt?: Date;
|
|
25
|
+
completedAt?: Date;
|
|
26
|
+
timeoutAt?: Date;
|
|
27
|
+
lastError?: string;
|
|
28
|
+
dedupeKey?: string;
|
|
29
|
+
tenantId?: string;
|
|
30
|
+
userId?: string;
|
|
31
|
+
traceId?: string;
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
result?: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for enqueueing a job.
|
|
37
|
+
*/
|
|
38
|
+
interface EnqueueOptions {
|
|
39
|
+
/** Delay execution by this many seconds */
|
|
40
|
+
delaySeconds?: number;
|
|
41
|
+
/** Key for deduplication (only one job with this key can be pending) */
|
|
42
|
+
dedupeKey?: string;
|
|
43
|
+
/** Maximum retry attempts (overrides job type default) */
|
|
44
|
+
maxRetries?: number;
|
|
45
|
+
/** Job priority (higher = more urgent) */
|
|
46
|
+
priority?: number;
|
|
47
|
+
/** Timeout in milliseconds */
|
|
48
|
+
timeoutMs?: number;
|
|
49
|
+
/** Tenant context */
|
|
50
|
+
tenantId?: string;
|
|
51
|
+
/** User who enqueued */
|
|
52
|
+
userId?: string;
|
|
53
|
+
/** Trace ID for distributed tracing */
|
|
54
|
+
traceId?: string;
|
|
55
|
+
/** Additional metadata */
|
|
56
|
+
metadata?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Job handler function.
|
|
60
|
+
*/
|
|
61
|
+
type JobHandler<TPayload = unknown, TResult = void> = (job: Job<TPayload>) => Promise<TResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Job queue interface.
|
|
64
|
+
*/
|
|
65
|
+
interface JobQueue {
|
|
66
|
+
/** Enqueue a new job */
|
|
67
|
+
enqueue<TPayload>(jobType: string, payload: TPayload, options?: EnqueueOptions): Promise<Job<TPayload>>;
|
|
68
|
+
/** Register a handler for a job type */
|
|
69
|
+
register<TPayload, TResult = void>(jobType: string, handler: JobHandler<TPayload, TResult>): void;
|
|
70
|
+
/** Start processing jobs */
|
|
71
|
+
start(): void;
|
|
72
|
+
/** Stop processing jobs gracefully */
|
|
73
|
+
stop(): Promise<void>;
|
|
74
|
+
/** Get job by ID */
|
|
75
|
+
getJob?(jobId: string): Promise<Job | null>;
|
|
76
|
+
/** Cancel a pending job */
|
|
77
|
+
cancelJob?(jobId: string): Promise<boolean>;
|
|
78
|
+
/** Get queue stats */
|
|
79
|
+
getStats?(): Promise<QueueStats>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Queue statistics.
|
|
83
|
+
*/
|
|
84
|
+
interface QueueStats {
|
|
85
|
+
pending: number;
|
|
86
|
+
running: number;
|
|
87
|
+
completed: number;
|
|
88
|
+
failed: number;
|
|
89
|
+
deadLetter: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Retry policy configuration.
|
|
93
|
+
*/
|
|
94
|
+
interface RetryPolicy {
|
|
95
|
+
/** Maximum number of retry attempts */
|
|
96
|
+
maxRetries: number;
|
|
97
|
+
/** Initial backoff in milliseconds */
|
|
98
|
+
initialBackoffMs: number;
|
|
99
|
+
/** Maximum backoff in milliseconds */
|
|
100
|
+
maxBackoffMs: number;
|
|
101
|
+
/** Backoff multiplier (exponential) */
|
|
102
|
+
multiplier: number;
|
|
103
|
+
/** Add jitter to backoff */
|
|
104
|
+
jitter: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Default retry policy.
|
|
108
|
+
*/
|
|
109
|
+
declare const DEFAULT_RETRY_POLICY: RetryPolicy;
|
|
110
|
+
/**
|
|
111
|
+
* Calculate backoff delay for a retry attempt.
|
|
112
|
+
*/
|
|
113
|
+
declare function calculateBackoff(attempt: number, policy?: RetryPolicy): number;
|
|
114
|
+
/**
|
|
115
|
+
* Job type definition.
|
|
116
|
+
*/
|
|
117
|
+
interface JobTypeDef<TPayload = unknown> {
|
|
118
|
+
type: string;
|
|
119
|
+
version: number;
|
|
120
|
+
payload: z.ZodType<TPayload>;
|
|
121
|
+
options?: Partial<RetryPolicy & {
|
|
122
|
+
timeoutMs: number;
|
|
123
|
+
}>;
|
|
124
|
+
description?: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Define a typed job type.
|
|
128
|
+
*/
|
|
129
|
+
declare function defineJobType<TPayload>(def: JobTypeDef<TPayload>): JobTypeDef<TPayload>;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { DEFAULT_RETRY_POLICY, EnqueueOptions, Job, JobHandler, JobQueue, JobStatus, JobTypeDef, QueueStats, RetryPolicy, calculateBackoff, defineJobType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod";const t={maxRetries:3,initialBackoffMs:1e3,maxBackoffMs:6e4,multiplier:2,jitter:!0};function n(e,n=t){let r=Math.min(n.initialBackoffMs*n.multiplier**(e-1),n.maxBackoffMs);if(n.jitter){let e=.8+Math.random()*.4;return Math.floor(r*e)}return r}function r(e){return e}export{t as DEFAULT_RETRY_POLICY,n as calculateBackoff,r as defineJobType};
|