@lssm/lib.jobs 0.0.0-canary-20251217080011 → 1.41.0
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/_virtual/rolldown_runtime.js +1 -42
- package/dist/contracts/index.js +1 -484
- package/dist/entities/index.js +1 -198
- package/dist/events.js +1 -303
- package/dist/handlers/gmail-sync-handler.js +1 -9
- package/dist/handlers/index.js +1 -12
- package/dist/handlers/ping-job.js +1 -13
- package/dist/handlers/storage-document-handler.js +1 -14
- package/dist/index.js +1 -18
- package/dist/jobs.feature.js +1 -101
- package/dist/queue/gcp-cloud-tasks.js +1 -61
- package/dist/queue/gcp-pubsub.js +1 -47
- package/dist/queue/index.js +1 -9
- package/dist/queue/memory-queue.js +1 -140
- package/dist/queue/register-defined-job.js +1 -15
- package/dist/queue/scaleway-sqs-queue.js +1 -175
- package/dist/queue/types.js +1 -3
- package/dist/scheduler/index.js +1 -145
- package/package.json +23 -25
- package/dist/contracts/dist/capabilities/openbanking.js +0 -88
- package/dist/contracts/dist/client/index.js +0 -5
- package/dist/contracts/dist/client/react/feature-render.js +0 -2
- package/dist/contracts/dist/client/react/form-render.js +0 -4
- package/dist/contracts/dist/client/react/index.js +0 -4
- package/dist/contracts/dist/contract-registry/index.js +0 -1
- package/dist/contracts/dist/contract-registry/schemas.js +0 -60
- package/dist/contracts/dist/docs/PUBLISHING.docblock.js +0 -16
- package/dist/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +0 -16
- package/dist/contracts/dist/docs/index.js +0 -29
- package/dist/contracts/dist/docs/presentations.js +0 -71
- package/dist/contracts/dist/docs/registry.js +0 -44
- package/dist/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +0 -80
- package/dist/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +0 -57
- package/dist/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/llm/llm-integration.docblock.js +0 -357
- package/dist/contracts/dist/docs/tech/mcp-endpoints.docblock.js +0 -37
- package/dist/contracts/dist/docs/tech/presentation-runtime.docblock.js +0 -16
- package/dist/contracts/dist/docs/tech/schema/README.docblock.js +0 -20
- package/dist/contracts/dist/docs/tech/studio/learning-events.docblock.js +0 -48
- package/dist/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +0 -79
- package/dist/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +0 -84
- package/dist/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +0 -45
- package/dist/contracts/dist/docs/tech/studio/project-routing.docblock.js +0 -67
- package/dist/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +0 -40
- package/dist/contracts/dist/docs/tech/studio/team-invitations.docblock.js +0 -69
- package/dist/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +0 -47
- package/dist/contracts/dist/docs/tech/studio/workspaces.docblock.js +0 -62
- package/dist/contracts/dist/docs/tech/telemetry-ingest.docblock.js +0 -155
- package/dist/contracts/dist/docs/tech/templates/runtime.docblock.js +0 -20
- package/dist/contracts/dist/docs/tech/vscode-extension.docblock.js +0 -101
- package/dist/contracts/dist/docs/tech/workflows/overview.docblock.js +0 -20
- package/dist/contracts/dist/events.js +0 -10
- package/dist/contracts/dist/experiments/evaluator.js +0 -1
- package/dist/contracts/dist/index.js +0 -71
- package/dist/contracts/dist/install.js +0 -2
- package/dist/contracts/dist/integrations/contracts.js +0 -377
- package/dist/contracts/dist/integrations/index.js +0 -18
- package/dist/contracts/dist/integrations/openbanking/contracts/accounts.js +0 -228
- package/dist/contracts/dist/integrations/openbanking/contracts/balances.js +0 -159
- package/dist/contracts/dist/integrations/openbanking/contracts/index.js +0 -3
- package/dist/contracts/dist/integrations/openbanking/contracts/transactions.js +0 -210
- package/dist/contracts/dist/integrations/openbanking/models.js +0 -242
- package/dist/contracts/dist/integrations/openbanking/telemetry.js +0 -13
- package/dist/contracts/dist/integrations/providers/elevenlabs.js +0 -52
- package/dist/contracts/dist/integrations/providers/gcs-storage.js +0 -75
- package/dist/contracts/dist/integrations/providers/gmail.js +0 -87
- package/dist/contracts/dist/integrations/providers/google-calendar.js +0 -66
- package/dist/contracts/dist/integrations/providers/index.js +0 -11
- package/dist/contracts/dist/integrations/providers/mistral.js +0 -68
- package/dist/contracts/dist/integrations/providers/postmark.js +0 -68
- package/dist/contracts/dist/integrations/providers/powens.js +0 -116
- package/dist/contracts/dist/integrations/providers/qdrant.js +0 -73
- package/dist/contracts/dist/integrations/providers/registry.js +0 -10
- package/dist/contracts/dist/integrations/providers/stripe.js +0 -83
- package/dist/contracts/dist/integrations/providers/twilio-sms.js +0 -61
- package/dist/contracts/dist/jobs/queue.js +0 -33
- package/dist/contracts/dist/jsonschema.js +0 -1
- package/dist/contracts/dist/knowledge/contracts.js +0 -306
- package/dist/contracts/dist/knowledge/index.js +0 -7
- package/dist/contracts/dist/knowledge/spaces/email-threads.js +0 -34
- package/dist/contracts/dist/knowledge/spaces/financial-docs.js +0 -34
- package/dist/contracts/dist/knowledge/spaces/financial-overview.js +0 -38
- package/dist/contracts/dist/knowledge/spaces/index.js +0 -6
- package/dist/contracts/dist/knowledge/spaces/product-canon.js +0 -34
- package/dist/contracts/dist/knowledge/spaces/support-faq.js +0 -37
- package/dist/contracts/dist/knowledge/spaces/uploaded-docs.js +0 -34
- package/dist/contracts/dist/llm/exporters.js +0 -19
- package/dist/contracts/dist/llm/index.js +0 -2
- package/dist/contracts/dist/llm/prompts.js +0 -1
- package/dist/contracts/dist/onboarding-base.js +0 -196
- package/dist/contracts/dist/openapi.js +0 -1
- package/dist/contracts/dist/ownership.js +0 -21
- package/dist/contracts/dist/presentations.js +0 -1
- package/dist/contracts/dist/presentations.v2.js +0 -11
- package/dist/contracts/dist/prompt.js +0 -1
- package/dist/contracts/dist/promptRegistry.js +0 -1
- package/dist/contracts/dist/regenerator/index.js +0 -1
- package/dist/contracts/dist/regenerator/service.js +0 -6
- package/dist/contracts/dist/registry.js +0 -2
- package/dist/contracts/dist/resources.js +0 -1
- package/dist/contracts/dist/schema/dist/EnumType.js +0 -2
- package/dist/contracts/dist/schema/dist/FieldType.js +0 -49
- package/dist/contracts/dist/schema/dist/ScalarTypeEnum.js +0 -236
- package/dist/contracts/dist/schema/dist/SchemaModel.js +0 -34
- package/dist/contracts/dist/schema/dist/entity/defineEntity.js +0 -1
- package/dist/contracts/dist/schema/dist/entity/index.js +0 -2
- package/dist/contracts/dist/schema/dist/entity/types.js +0 -1
- package/dist/contracts/dist/schema/dist/index.js +0 -6
- package/dist/contracts/dist/server/graphql-pothos.js +0 -6
- package/dist/contracts/dist/server/index.js +0 -8
- package/dist/contracts/dist/server/mcp/createMcpServer.js +0 -4
- package/dist/contracts/dist/server/mcp/registerPresentations.js +0 -2
- package/dist/contracts/dist/server/mcp/registerPrompts.js +0 -1
- package/dist/contracts/dist/server/mcp/registerResources.js +0 -2
- package/dist/contracts/dist/server/mcp/registerTools.js +0 -1
- package/dist/contracts/dist/server/provider-mcp.js +0 -1
- package/dist/contracts/dist/server/rest-elysia.js +0 -1
- package/dist/contracts/dist/server/rest-express.js +0 -1
- package/dist/contracts/dist/server/rest-generic.js +0 -1
- package/dist/contracts/dist/server/rest-next-app.js +0 -1
- package/dist/contracts/dist/server/rest-next-pages.js +0 -1
- package/dist/contracts/dist/spec.js +0 -34
- package/dist/contracts/dist/telemetry/index.js +0 -1
- package/dist/contracts/dist/telemetry/tracker.js +0 -1
- package/dist/contracts/dist/tests/index.js +0 -1
- package/dist/contracts/dist/tests/runner.js +0 -2
- package/dist/contracts/dist/workflow/index.js +0 -1
- package/dist/contracts/dist/workflow/runner.js +0 -1
- package/dist/contracts/index.d.ts +0 -546
- package/dist/entities/index.d.ts +0 -144
- package/dist/events.d.ts +0 -387
- package/dist/handlers/gmail-sync-handler.d.ts +0 -9
- package/dist/handlers/index.d.ts +0 -9
- package/dist/handlers/ping-job.d.ts +0 -10
- package/dist/handlers/storage-document-handler.d.ts +0 -12
- package/dist/index.d.ts +0 -24
- package/dist/jobs.feature.d.ts +0 -11
- package/dist/queue/gcp-cloud-tasks.d.ts +0 -41
- package/dist/queue/gcp-pubsub.d.ts +0 -25
- package/dist/queue/index.d.ts +0 -15
- package/dist/queue/memory-queue.d.ts +0 -34
- package/dist/queue/register-defined-job.d.ts +0 -7
- package/dist/queue/scaleway-sqs-queue.d.ts +0 -38
- package/dist/queue/types.d.ts +0 -7
- package/dist/scheduler/index.d.ts +0 -92
- package/dist/schema/dist/EnumType.js +0 -2
- package/dist/schema/dist/FieldType.js +0 -49
- package/dist/schema/dist/ScalarTypeEnum.js +0 -236
- package/dist/schema/dist/SchemaModel.js +0 -39
- package/dist/schema/dist/entity/defineEntity.js +0 -236
- package/dist/schema/dist/entity/index.js +0 -2
- package/dist/schema/dist/entity/types.js +0 -1
- package/dist/schema/dist/index.js +0 -6
package/dist/jobs.feature.js
CHANGED
|
@@ -1,101 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Jobs feature module that bundles job queue management,
|
|
4
|
-
* background processing, and scheduled task capabilities.
|
|
5
|
-
*/
|
|
6
|
-
const JobsFeature = {
|
|
7
|
-
meta: {
|
|
8
|
-
key: "jobs",
|
|
9
|
-
title: "Background Jobs",
|
|
10
|
-
description: "Background job processing, scheduling, and queue management",
|
|
11
|
-
domain: "platform",
|
|
12
|
-
owners: ["@platform.jobs"],
|
|
13
|
-
tags: [
|
|
14
|
-
"jobs",
|
|
15
|
-
"queue",
|
|
16
|
-
"background",
|
|
17
|
-
"scheduler"
|
|
18
|
-
],
|
|
19
|
-
stability: "stable"
|
|
20
|
-
},
|
|
21
|
-
operations: [
|
|
22
|
-
{
|
|
23
|
-
name: "jobs.enqueue",
|
|
24
|
-
version: 1
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: "jobs.cancel",
|
|
28
|
-
version: 1
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "jobs.get",
|
|
32
|
-
version: 1
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "jobs.stats",
|
|
36
|
-
version: 1
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "jobs.schedule.create",
|
|
40
|
-
version: 1
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "jobs.schedule.toggle",
|
|
44
|
-
version: 1
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: "jobs.schedule.list",
|
|
48
|
-
version: 1
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
events: [
|
|
52
|
-
{
|
|
53
|
-
name: "job.enqueued",
|
|
54
|
-
version: 1
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "job.started",
|
|
58
|
-
version: 1
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: "job.completed",
|
|
62
|
-
version: 1
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: "job.failed",
|
|
66
|
-
version: 1
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: "job.retrying",
|
|
70
|
-
version: 1
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: "job.dead_lettered",
|
|
74
|
-
version: 1
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: "job.cancelled",
|
|
78
|
-
version: 1
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: "scheduler.job_triggered",
|
|
82
|
-
version: 1
|
|
83
|
-
}
|
|
84
|
-
],
|
|
85
|
-
presentations: [],
|
|
86
|
-
opToPresentation: [],
|
|
87
|
-
presentationsTargets: [],
|
|
88
|
-
capabilities: {
|
|
89
|
-
provides: [{
|
|
90
|
-
key: "jobs",
|
|
91
|
-
version: 1
|
|
92
|
-
}, {
|
|
93
|
-
key: "scheduler",
|
|
94
|
-
version: 1
|
|
95
|
-
}],
|
|
96
|
-
requires: []
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
//#endregion
|
|
101
|
-
export { JobsFeature };
|
|
1
|
+
const e={meta:{key:`jobs`,title:`Background Jobs`,description:`Background job processing, scheduling, and queue management`,domain:`platform`,owners:[`@platform.jobs`],tags:[`jobs`,`queue`,`background`,`scheduler`],stability:`stable`},operations:[{name:`jobs.enqueue`,version:1},{name:`jobs.cancel`,version:1},{name:`jobs.get`,version:1},{name:`jobs.stats`,version:1},{name:`jobs.schedule.create`,version:1},{name:`jobs.schedule.toggle`,version:1},{name:`jobs.schedule.list`,version:1}],events:[{name:`job.enqueued`,version:1},{name:`job.started`,version:1},{name:`job.completed`,version:1},{name:`job.failed`,version:1},{name:`job.retrying`,version:1},{name:`job.dead_lettered`,version:1},{name:`job.cancelled`,version:1},{name:`scheduler.job_triggered`,version:1}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{provides:[{key:`jobs`,version:1},{key:`scheduler`,version:1}],requires:[]}};export{e as JobsFeature};
|
|
@@ -1,61 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./types.js";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
|
|
5
|
-
//#region src/queue/gcp-cloud-tasks.ts
|
|
6
|
-
var GcpCloudTasksQueue = class {
|
|
7
|
-
handlers = /* @__PURE__ */ new Map();
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.options = options;
|
|
10
|
-
}
|
|
11
|
-
async enqueue(jobType, payload, options = {}) {
|
|
12
|
-
const now = /* @__PURE__ */ new Date();
|
|
13
|
-
const enqueueTime = options.delaySeconds != null ? { seconds: Math.floor(Date.now() / 1e3) + options.delaySeconds } : void 0;
|
|
14
|
-
const body = Buffer.from(JSON.stringify({
|
|
15
|
-
id: randomUUID(),
|
|
16
|
-
type: jobType,
|
|
17
|
-
payload
|
|
18
|
-
}), "utf-8");
|
|
19
|
-
await this.options.client.createTask({
|
|
20
|
-
parent: `projects/${this.options.projectId}/locations/${this.options.location}/queues/${this.options.queue}`,
|
|
21
|
-
task: {
|
|
22
|
-
httpRequest: {
|
|
23
|
-
httpMethod: "POST",
|
|
24
|
-
url: this.options.resolveUrl(jobType),
|
|
25
|
-
body,
|
|
26
|
-
headers: { "Content-Type": "application/json" },
|
|
27
|
-
oidcToken: this.options.serviceAccountEmail ? { serviceAccountEmail: this.options.serviceAccountEmail } : void 0
|
|
28
|
-
},
|
|
29
|
-
scheduleTime: enqueueTime
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return {
|
|
33
|
-
id: randomUUID(),
|
|
34
|
-
type: jobType,
|
|
35
|
-
version: 1,
|
|
36
|
-
payload,
|
|
37
|
-
status: "pending",
|
|
38
|
-
priority: options.priority ?? 0,
|
|
39
|
-
attempts: 0,
|
|
40
|
-
maxRetries: options.maxRetries ?? DEFAULT_RETRY_POLICY.maxRetries,
|
|
41
|
-
createdAt: now,
|
|
42
|
-
updatedAt: now,
|
|
43
|
-
scheduledAt: options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1e3) : now,
|
|
44
|
-
dedupeKey: options.dedupeKey,
|
|
45
|
-
tenantId: options.tenantId,
|
|
46
|
-
userId: options.userId,
|
|
47
|
-
traceId: options.traceId,
|
|
48
|
-
metadata: options.metadata
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
register(jobType, handler) {
|
|
52
|
-
this.handlers.set(jobType, handler);
|
|
53
|
-
}
|
|
54
|
-
start() {}
|
|
55
|
-
async stop() {
|
|
56
|
-
this.handlers.clear();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
|
-
export { GcpCloudTasksQueue };
|
|
1
|
+
import{types_exports as e}from"./types.js";import{randomUUID as t}from"node:crypto";var n=class{handlers=new Map;constructor(e){this.options=e}async enqueue(n,r,i={}){let a=new Date,o=i.delaySeconds==null?void 0:{seconds:Math.floor(Date.now()/1e3)+i.delaySeconds},s=Buffer.from(JSON.stringify({id:t(),type:n,payload:r}),`utf-8`);return await this.options.client.createTask({parent:`projects/${this.options.projectId}/locations/${this.options.location}/queues/${this.options.queue}`,task:{httpRequest:{httpMethod:`POST`,url:this.options.resolveUrl(n),body:s,headers:{"Content-Type":`application/json`},oidcToken:this.options.serviceAccountEmail?{serviceAccountEmail:this.options.serviceAccountEmail}:void 0},scheduleTime:o}}),{id:t(),type:n,version:1,payload:r,status:`pending`,priority:i.priority??0,attempts:0,maxRetries:i.maxRetries??e.DEFAULT_RETRY_POLICY.maxRetries,createdAt:a,updatedAt:a,scheduledAt:i.delaySeconds?new Date(a.getTime()+i.delaySeconds*1e3):a,dedupeKey:i.dedupeKey,tenantId:i.tenantId,userId:i.userId,traceId:i.traceId,metadata:i.metadata}}register(e,t){this.handlers.set(e,t)}start(){}async stop(){this.handlers.clear()}};export{n as GcpCloudTasksQueue};
|
package/dist/queue/gcp-pubsub.js
CHANGED
|
@@ -1,47 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./types.js";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
|
|
5
|
-
//#region src/queue/gcp-pubsub.ts
|
|
6
|
-
var GcpPubSubQueue = class {
|
|
7
|
-
handlers = /* @__PURE__ */ new Map();
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.options = options;
|
|
10
|
-
}
|
|
11
|
-
async enqueue(jobType, payload, options = {}) {
|
|
12
|
-
const now = /* @__PURE__ */ new Date();
|
|
13
|
-
await this.options.client.topic(this.options.topicName).publishMessage({ data: Buffer.from(JSON.stringify({
|
|
14
|
-
id: randomUUID(),
|
|
15
|
-
type: jobType,
|
|
16
|
-
payload
|
|
17
|
-
}), "utf-8") });
|
|
18
|
-
return {
|
|
19
|
-
id: randomUUID(),
|
|
20
|
-
type: jobType,
|
|
21
|
-
version: 1,
|
|
22
|
-
payload,
|
|
23
|
-
status: "pending",
|
|
24
|
-
priority: options.priority ?? 0,
|
|
25
|
-
attempts: 0,
|
|
26
|
-
maxRetries: options.maxRetries ?? DEFAULT_RETRY_POLICY.maxRetries,
|
|
27
|
-
createdAt: now,
|
|
28
|
-
updatedAt: now,
|
|
29
|
-
scheduledAt: options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1e3) : now,
|
|
30
|
-
dedupeKey: options.dedupeKey,
|
|
31
|
-
tenantId: options.tenantId,
|
|
32
|
-
userId: options.userId,
|
|
33
|
-
traceId: options.traceId,
|
|
34
|
-
metadata: options.metadata
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
register(jobType, handler) {
|
|
38
|
-
this.handlers.set(jobType, handler);
|
|
39
|
-
}
|
|
40
|
-
start() {}
|
|
41
|
-
async stop() {
|
|
42
|
-
this.handlers.clear();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
export { GcpPubSubQueue };
|
|
1
|
+
import{types_exports as e}from"./types.js";import{randomUUID as t}from"node:crypto";var n=class{handlers=new Map;constructor(e){this.options=e}async enqueue(n,r,i={}){let a=new Date;return await this.options.client.topic(this.options.topicName).publishMessage({data:Buffer.from(JSON.stringify({id:t(),type:n,payload:r}),`utf-8`)}),{id:t(),type:n,version:1,payload:r,status:`pending`,priority:i.priority??0,attempts:0,maxRetries:i.maxRetries??e.DEFAULT_RETRY_POLICY.maxRetries,createdAt:a,updatedAt:a,scheduledAt:i.delaySeconds?new Date(a.getTime()+i.delaySeconds*1e3):a,dedupeKey:i.dedupeKey,tenantId:i.tenantId,userId:i.userId,traceId:i.traceId,metadata:i.metadata}}register(e,t){this.handlers.set(e,t)}start(){}async stop(){this.handlers.clear()}};export{n as GcpPubSubQueue};
|
package/dist/queue/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./types.js";
|
|
3
|
-
import { MemoryJobQueue } from "./memory-queue.js";
|
|
4
|
-
import { ScalewaySqsJobQueue } from "./scaleway-sqs-queue.js";
|
|
5
|
-
import { GcpCloudTasksQueue } from "./gcp-cloud-tasks.js";
|
|
6
|
-
import { GcpPubSubQueue } from "./gcp-pubsub.js";
|
|
7
|
-
import { registerDefinedJob } from "./register-defined-job.js";
|
|
8
|
-
|
|
9
|
-
export { DEFAULT_RETRY_POLICY, GcpCloudTasksQueue, GcpPubSubQueue, MemoryJobQueue, ScalewaySqsJobQueue, calculateBackoff, defineJobType, registerDefinedJob };
|
|
1
|
+
import{__export as e,__reExport as t}from"../_virtual/rolldown_runtime.js";import{types_exports as n}from"./types.js";import{MemoryJobQueue as r}from"./memory-queue.js";import{ScalewaySqsJobQueue as i}from"./scaleway-sqs-queue.js";import{GcpCloudTasksQueue as a}from"./gcp-cloud-tasks.js";import{GcpPubSubQueue as o}from"./gcp-pubsub.js";import{registerDefinedJob as s}from"./register-defined-job.js";export*from"@lssm/lib.contracts/jobs/queue";var c=e({GcpCloudTasksQueue:()=>a,GcpPubSubQueue:()=>o,MemoryJobQueue:()=>r,ScalewaySqsJobQueue:()=>i,registerDefinedJob:()=>s});t(c,n);export{a as GcpCloudTasksQueue,o as GcpPubSubQueue,r as MemoryJobQueue,i as ScalewaySqsJobQueue,c as queue_exports,s as registerDefinedJob};
|
|
@@ -1,140 +1 @@
|
|
|
1
|
-
import { DEFAULT_RETRY_POLICY,
|
|
2
|
-
import "./types.js";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
|
|
5
|
-
//#region src/queue/memory-queue.ts
|
|
6
|
-
/**
|
|
7
|
-
* In-memory job queue for development and testing.
|
|
8
|
-
*/
|
|
9
|
-
var MemoryJobQueue = class {
|
|
10
|
-
jobs = /* @__PURE__ */ new Map();
|
|
11
|
-
handlers = /* @__PURE__ */ new Map();
|
|
12
|
-
timer;
|
|
13
|
-
activeCount = 0;
|
|
14
|
-
pollIntervalMs;
|
|
15
|
-
concurrency;
|
|
16
|
-
retryPolicy;
|
|
17
|
-
constructor(options = {}) {
|
|
18
|
-
this.pollIntervalMs = options.pollIntervalMs ?? 200;
|
|
19
|
-
this.concurrency = options.concurrency ?? 5;
|
|
20
|
-
this.retryPolicy = options.retryPolicy ?? DEFAULT_RETRY_POLICY;
|
|
21
|
-
}
|
|
22
|
-
async enqueue(jobType, payload, options = {}) {
|
|
23
|
-
if (options.dedupeKey) {
|
|
24
|
-
const existing = Array.from(this.jobs.values()).find((j) => j.dedupeKey === options.dedupeKey && j.status === "pending");
|
|
25
|
-
if (existing) return existing;
|
|
26
|
-
}
|
|
27
|
-
const now = /* @__PURE__ */ new Date();
|
|
28
|
-
const scheduledAt = options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1e3) : now;
|
|
29
|
-
const job = {
|
|
30
|
-
id: randomUUID(),
|
|
31
|
-
type: jobType,
|
|
32
|
-
version: 1,
|
|
33
|
-
payload,
|
|
34
|
-
status: "pending",
|
|
35
|
-
priority: options.priority ?? 0,
|
|
36
|
-
attempts: 0,
|
|
37
|
-
maxRetries: options.maxRetries ?? this.retryPolicy.maxRetries,
|
|
38
|
-
createdAt: now,
|
|
39
|
-
updatedAt: now,
|
|
40
|
-
scheduledAt,
|
|
41
|
-
dedupeKey: options.dedupeKey,
|
|
42
|
-
tenantId: options.tenantId,
|
|
43
|
-
userId: options.userId,
|
|
44
|
-
traceId: options.traceId,
|
|
45
|
-
metadata: options.metadata
|
|
46
|
-
};
|
|
47
|
-
if (options.timeoutMs) job.timeoutAt = new Date(now.getTime() + options.timeoutMs);
|
|
48
|
-
this.jobs.set(job.id, job);
|
|
49
|
-
return job;
|
|
50
|
-
}
|
|
51
|
-
register(jobType, handler) {
|
|
52
|
-
this.handlers.set(jobType, handler);
|
|
53
|
-
}
|
|
54
|
-
start() {
|
|
55
|
-
if (this.timer) return;
|
|
56
|
-
this.timer = setInterval(() => {
|
|
57
|
-
this.processNext();
|
|
58
|
-
}, this.pollIntervalMs);
|
|
59
|
-
}
|
|
60
|
-
async stop() {
|
|
61
|
-
if (this.timer) {
|
|
62
|
-
clearInterval(this.timer);
|
|
63
|
-
this.timer = void 0;
|
|
64
|
-
}
|
|
65
|
-
while (this.activeCount > 0) await new Promise((resolve) => setTimeout(resolve, 50));
|
|
66
|
-
}
|
|
67
|
-
async getJob(jobId) {
|
|
68
|
-
return this.jobs.get(jobId) ?? null;
|
|
69
|
-
}
|
|
70
|
-
async cancelJob(jobId) {
|
|
71
|
-
const job = this.jobs.get(jobId);
|
|
72
|
-
if (!job || job.status !== "pending") return false;
|
|
73
|
-
job.status = "cancelled";
|
|
74
|
-
job.updatedAt = /* @__PURE__ */ new Date();
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
async getStats() {
|
|
78
|
-
const stats = {
|
|
79
|
-
pending: 0,
|
|
80
|
-
running: 0,
|
|
81
|
-
completed: 0,
|
|
82
|
-
failed: 0,
|
|
83
|
-
deadLetter: 0
|
|
84
|
-
};
|
|
85
|
-
for (const job of this.jobs.values()) switch (job.status) {
|
|
86
|
-
case "pending":
|
|
87
|
-
stats.pending++;
|
|
88
|
-
break;
|
|
89
|
-
case "running":
|
|
90
|
-
stats.running++;
|
|
91
|
-
break;
|
|
92
|
-
case "completed":
|
|
93
|
-
stats.completed++;
|
|
94
|
-
break;
|
|
95
|
-
case "failed":
|
|
96
|
-
stats.failed++;
|
|
97
|
-
break;
|
|
98
|
-
case "dead_letter":
|
|
99
|
-
stats.deadLetter++;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
return stats;
|
|
103
|
-
}
|
|
104
|
-
async processNext() {
|
|
105
|
-
if (this.activeCount >= this.concurrency) return;
|
|
106
|
-
const now = /* @__PURE__ */ new Date();
|
|
107
|
-
const job = Array.from(this.jobs.values()).filter((j) => j.status === "pending" && (!j.scheduledAt || j.scheduledAt <= now)).sort((a, b) => {
|
|
108
|
-
if (a.priority !== b.priority) return b.priority - a.priority;
|
|
109
|
-
return (a.scheduledAt?.getTime() ?? 0) - (b.scheduledAt?.getTime() ?? 0);
|
|
110
|
-
})[0];
|
|
111
|
-
if (!job) return;
|
|
112
|
-
const handler = this.handlers.get(job.type);
|
|
113
|
-
if (!handler) return;
|
|
114
|
-
this.activeCount++;
|
|
115
|
-
job.status = "running";
|
|
116
|
-
job.startedAt = /* @__PURE__ */ new Date();
|
|
117
|
-
job.updatedAt = /* @__PURE__ */ new Date();
|
|
118
|
-
job.attempts += 1;
|
|
119
|
-
try {
|
|
120
|
-
const result = await handler(job);
|
|
121
|
-
job.status = "completed";
|
|
122
|
-
job.completedAt = /* @__PURE__ */ new Date();
|
|
123
|
-
job.result = result;
|
|
124
|
-
} catch (error) {
|
|
125
|
-
job.lastError = error instanceof Error ? error.message : "Unknown error";
|
|
126
|
-
if (job.attempts >= job.maxRetries) job.status = "dead_letter";
|
|
127
|
-
else {
|
|
128
|
-
const backoff = calculateBackoff(job.attempts, this.retryPolicy);
|
|
129
|
-
job.status = "pending";
|
|
130
|
-
job.scheduledAt = new Date(Date.now() + backoff);
|
|
131
|
-
}
|
|
132
|
-
} finally {
|
|
133
|
-
job.updatedAt = /* @__PURE__ */ new Date();
|
|
134
|
-
this.activeCount--;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
export { MemoryJobQueue };
|
|
1
|
+
import{types_exports as e}from"./types.js";import{randomUUID as t}from"node:crypto";var n=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.DEFAULT_RETRY_POLICY}async enqueue(e,n,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:t(),type:e,version:1,payload:n,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 t=new Date,n=Array.from(this.jobs.values()).filter(e=>e.status===`pending`&&(!e.scheduledAt||e.scheduledAt<=t)).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(t){if(n.lastError=t instanceof Error?t.message:`Unknown error`,n.attempts>=n.maxRetries)n.status=`dead_letter`;else{let t=(0,e.calculateBackoff)(n.attempts,this.retryPolicy);n.status=`pending`,n.scheduledAt=new Date(Date.now()+t)}}finally{n.updatedAt=new Date,this.activeCount--}}}};export{n as MemoryJobQueue};
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function registerDefinedJob(queue, def) {
|
|
3
|
-
const wrapped = async (job) => {
|
|
4
|
-
const payload = def.schema.parse(job.payload);
|
|
5
|
-
const typedJob = {
|
|
6
|
-
...job,
|
|
7
|
-
payload
|
|
8
|
-
};
|
|
9
|
-
await def.handler(payload, typedJob);
|
|
10
|
-
};
|
|
11
|
-
queue.register(def.type, wrapped);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { registerDefinedJob };
|
|
1
|
+
function e(e,t){e.register(t.type,async e=>{let n=t.schema.parse(e.payload),r={...e,payload:n};await t.handler(n,r)})}export{e as registerDefinedJob};
|
|
@@ -1,175 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./types.js";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { DeleteMessageCommand, ReceiveMessageCommand, SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
|
|
5
|
-
|
|
6
|
-
//#region src/queue/scaleway-sqs-queue.ts
|
|
7
|
-
var ScalewaySqsJobQueue = class {
|
|
8
|
-
sqs;
|
|
9
|
-
queueUrl;
|
|
10
|
-
waitTimeSeconds;
|
|
11
|
-
maxNumberOfMessages;
|
|
12
|
-
visibilityTimeoutSeconds;
|
|
13
|
-
handlers = /* @__PURE__ */ new Map();
|
|
14
|
-
logger;
|
|
15
|
-
running = false;
|
|
16
|
-
constructor(config) {
|
|
17
|
-
this.logger = config.logger;
|
|
18
|
-
const accessKeyId = config.credentials?.accessKeyId ?? process.env.SCALEWAY_ACCESS_KEY_QUEUE;
|
|
19
|
-
const secretAccessKey = config.credentials?.secretAccessKey ?? process.env.SCALEWAY_SECRET_KEY_QUEUE;
|
|
20
|
-
if (!accessKeyId || !secretAccessKey) throw new Error("Missing SCALEWAY_ACCESS_KEY_QUEUE / SCALEWAY_SECRET_KEY_QUEUE in env");
|
|
21
|
-
this.sqs = new SQSClient({
|
|
22
|
-
region: config.region ?? process.env.SCALEWAY_REGION ?? "par",
|
|
23
|
-
endpoint: config.endpoint ?? "https://sqs.mnq.fr-par.scaleway.com",
|
|
24
|
-
credentials: {
|
|
25
|
-
accessKeyId,
|
|
26
|
-
secretAccessKey
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
this.queueUrl = config.queueUrl;
|
|
30
|
-
this.waitTimeSeconds = config.waitTimeSeconds ?? 20;
|
|
31
|
-
this.maxNumberOfMessages = config.maxNumberOfMessages ?? 5;
|
|
32
|
-
this.visibilityTimeoutSeconds = config.visibilityTimeoutSeconds ?? 60;
|
|
33
|
-
}
|
|
34
|
-
async enqueue(jobType, payload, options = {}) {
|
|
35
|
-
const id = randomUUID();
|
|
36
|
-
const now = /* @__PURE__ */ new Date();
|
|
37
|
-
const scheduledAt = options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1e3) : now;
|
|
38
|
-
const envelope = {
|
|
39
|
-
id,
|
|
40
|
-
type: jobType,
|
|
41
|
-
payload
|
|
42
|
-
};
|
|
43
|
-
await this.sqs.send(new SendMessageCommand({
|
|
44
|
-
QueueUrl: this.queueUrl,
|
|
45
|
-
MessageBody: JSON.stringify(envelope),
|
|
46
|
-
DelaySeconds: options.delaySeconds ?? 0
|
|
47
|
-
}));
|
|
48
|
-
return {
|
|
49
|
-
id,
|
|
50
|
-
type: jobType,
|
|
51
|
-
version: 1,
|
|
52
|
-
payload,
|
|
53
|
-
status: "pending",
|
|
54
|
-
priority: options.priority ?? 0,
|
|
55
|
-
attempts: 0,
|
|
56
|
-
maxRetries: options.maxRetries ?? DEFAULT_RETRY_POLICY.maxRetries,
|
|
57
|
-
createdAt: now,
|
|
58
|
-
updatedAt: now,
|
|
59
|
-
scheduledAt,
|
|
60
|
-
dedupeKey: options.dedupeKey,
|
|
61
|
-
tenantId: options.tenantId,
|
|
62
|
-
userId: options.userId,
|
|
63
|
-
traceId: options.traceId,
|
|
64
|
-
metadata: options.metadata
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
register(jobType, handler) {
|
|
68
|
-
if (this.handlers.has(jobType)) throw new Error(`Handler already registered for job type "${jobType}"`);
|
|
69
|
-
this.handlers.set(jobType, handler);
|
|
70
|
-
}
|
|
71
|
-
start() {
|
|
72
|
-
if (this.running) return;
|
|
73
|
-
this.running = true;
|
|
74
|
-
this.pollLoop().catch((error) => {
|
|
75
|
-
this.logger?.error?.("jobs.queue.scaleway_sqs.poll_loop_fatal", { error: error instanceof Error ? error.message : String(error) });
|
|
76
|
-
this.running = false;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async stop() {
|
|
80
|
-
this.running = false;
|
|
81
|
-
}
|
|
82
|
-
async pollLoop() {
|
|
83
|
-
this.logger?.info?.("jobs.queue.scaleway_sqs.started", { queueUrl: this.queueUrl });
|
|
84
|
-
while (this.running) try {
|
|
85
|
-
const messages = (await this.sqs.send(new ReceiveMessageCommand({
|
|
86
|
-
QueueUrl: this.queueUrl,
|
|
87
|
-
MaxNumberOfMessages: this.maxNumberOfMessages,
|
|
88
|
-
WaitTimeSeconds: this.waitTimeSeconds,
|
|
89
|
-
VisibilityTimeout: this.visibilityTimeoutSeconds,
|
|
90
|
-
MessageSystemAttributeNames: ["ApproximateReceiveCount"]
|
|
91
|
-
}))).Messages ?? [];
|
|
92
|
-
if (messages.length === 0) continue;
|
|
93
|
-
for (const msg of messages) {
|
|
94
|
-
if (!msg.Body || !msg.ReceiptHandle) {
|
|
95
|
-
this.logger?.warn?.("jobs.queue.scaleway_sqs.invalid_message", {
|
|
96
|
-
messageId: msg.MessageId,
|
|
97
|
-
reason: "missing_body_or_receipt"
|
|
98
|
-
});
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
let envelope;
|
|
102
|
-
try {
|
|
103
|
-
envelope = JSON.parse(msg.Body);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
this.logger?.warn?.("jobs.queue.scaleway_sqs.parse_failed", {
|
|
106
|
-
messageId: msg.MessageId,
|
|
107
|
-
error: err instanceof Error ? err.message : String(err)
|
|
108
|
-
});
|
|
109
|
-
await this.deleteMessage(msg.ReceiptHandle);
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const handler = this.handlers.get(envelope.type);
|
|
113
|
-
if (!handler) {
|
|
114
|
-
this.logger?.warn?.("jobs.queue.scaleway_sqs.missing_handler", {
|
|
115
|
-
jobType: envelope.type,
|
|
116
|
-
messageId: msg.MessageId
|
|
117
|
-
});
|
|
118
|
-
await this.deleteMessage(msg.ReceiptHandle);
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
const now = /* @__PURE__ */ new Date();
|
|
122
|
-
const attempts = parseInt(msg.Attributes?.ApproximateReceiveCount ?? "1", 10);
|
|
123
|
-
const job = {
|
|
124
|
-
id: envelope.id,
|
|
125
|
-
type: envelope.type,
|
|
126
|
-
version: 1,
|
|
127
|
-
payload: envelope.payload,
|
|
128
|
-
status: "pending",
|
|
129
|
-
priority: 0,
|
|
130
|
-
attempts,
|
|
131
|
-
maxRetries: DEFAULT_RETRY_POLICY.maxRetries,
|
|
132
|
-
createdAt: now,
|
|
133
|
-
updatedAt: now
|
|
134
|
-
};
|
|
135
|
-
job.status = "running";
|
|
136
|
-
job.updatedAt = /* @__PURE__ */ new Date();
|
|
137
|
-
try {
|
|
138
|
-
await handler(job);
|
|
139
|
-
job.status = "completed";
|
|
140
|
-
job.updatedAt = /* @__PURE__ */ new Date();
|
|
141
|
-
await this.deleteMessage(msg.ReceiptHandle);
|
|
142
|
-
} catch (err) {
|
|
143
|
-
job.status = "failed";
|
|
144
|
-
job.lastError = err instanceof Error ? err.message : "Unknown job error";
|
|
145
|
-
job.updatedAt = /* @__PURE__ */ new Date();
|
|
146
|
-
this.logger?.error?.("jobs.queue.scaleway_sqs.job_failed", {
|
|
147
|
-
jobType: job.type,
|
|
148
|
-
jobId: job.id,
|
|
149
|
-
error: err instanceof Error ? err.message : String(err)
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
} catch (err) {
|
|
154
|
-
this.logger?.error?.("jobs.queue.scaleway_sqs.poll_error", { error: err instanceof Error ? err.message : String(err) });
|
|
155
|
-
await this.sleep(5e3);
|
|
156
|
-
}
|
|
157
|
-
this.logger?.info?.("jobs.queue.scaleway_sqs.stopped", { queueUrl: this.queueUrl });
|
|
158
|
-
}
|
|
159
|
-
async deleteMessage(receiptHandle) {
|
|
160
|
-
try {
|
|
161
|
-
await this.sqs.send(new DeleteMessageCommand({
|
|
162
|
-
QueueUrl: this.queueUrl,
|
|
163
|
-
ReceiptHandle: receiptHandle
|
|
164
|
-
}));
|
|
165
|
-
} catch (err) {
|
|
166
|
-
this.logger?.warn?.("jobs.queue.scaleway_sqs.delete_failed", { error: err instanceof Error ? err.message : String(err) });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async sleep(ms) {
|
|
170
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
//#endregion
|
|
175
|
-
export { ScalewaySqsJobQueue };
|
|
1
|
+
import{types_exports as e}from"./types.js";import{randomUUID as t}from"node:crypto";import{DeleteMessageCommand as n,ReceiveMessageCommand as r,SQSClient as i,SendMessageCommand as a}from"@aws-sdk/client-sqs";var o=class{sqs;queueUrl;waitTimeSeconds;maxNumberOfMessages;visibilityTimeoutSeconds;handlers=new Map;logger;running=!1;constructor(e){this.logger=e.logger;let t=e.credentials?.accessKeyId??process.env.SCALEWAY_ACCESS_KEY_QUEUE,n=e.credentials?.secretAccessKey??process.env.SCALEWAY_SECRET_KEY_QUEUE;if(!t||!n)throw Error(`Missing SCALEWAY_ACCESS_KEY_QUEUE / SCALEWAY_SECRET_KEY_QUEUE in env`);this.sqs=new i({region:e.region??process.env.SCALEWAY_REGION??`par`,endpoint:e.endpoint??`https://sqs.mnq.fr-par.scaleway.com`,credentials:{accessKeyId:t,secretAccessKey:n}}),this.queueUrl=e.queueUrl,this.waitTimeSeconds=e.waitTimeSeconds??20,this.maxNumberOfMessages=e.maxNumberOfMessages??5,this.visibilityTimeoutSeconds=e.visibilityTimeoutSeconds??60}async enqueue(n,r,i={}){let o=t(),s=new Date,c=i.delaySeconds?new Date(s.getTime()+i.delaySeconds*1e3):s,l={id:o,type:n,payload:r};return await this.sqs.send(new a({QueueUrl:this.queueUrl,MessageBody:JSON.stringify(l),DelaySeconds:i.delaySeconds??0})),{id:o,type:n,version:1,payload:r,status:`pending`,priority:i.priority??0,attempts:0,maxRetries:i.maxRetries??e.DEFAULT_RETRY_POLICY.maxRetries,createdAt:s,updatedAt:s,scheduledAt:c,dedupeKey:i.dedupeKey,tenantId:i.tenantId,userId:i.userId,traceId:i.traceId,metadata:i.metadata}}register(e,t){if(this.handlers.has(e))throw Error(`Handler already registered for job type "${e}"`);this.handlers.set(e,t)}start(){this.running||(this.running=!0,this.pollLoop().catch(e=>{this.logger?.error?.(`jobs.queue.scaleway_sqs.poll_loop_fatal`,{error:e instanceof Error?e.message:String(e)}),this.running=!1}))}async stop(){this.running=!1}async pollLoop(){for(this.logger?.info?.(`jobs.queue.scaleway_sqs.started`,{queueUrl:this.queueUrl});this.running;)try{let t=(await this.sqs.send(new r({QueueUrl:this.queueUrl,MaxNumberOfMessages:this.maxNumberOfMessages,WaitTimeSeconds:this.waitTimeSeconds,VisibilityTimeout:this.visibilityTimeoutSeconds,MessageSystemAttributeNames:[`ApproximateReceiveCount`]}))).Messages??[];if(t.length===0)continue;for(let n of t){if(!n.Body||!n.ReceiptHandle){this.logger?.warn?.(`jobs.queue.scaleway_sqs.invalid_message`,{messageId:n.MessageId,reason:`missing_body_or_receipt`});continue}let t;try{t=JSON.parse(n.Body)}catch(e){this.logger?.warn?.(`jobs.queue.scaleway_sqs.parse_failed`,{messageId:n.MessageId,error:e instanceof Error?e.message:String(e)}),await this.deleteMessage(n.ReceiptHandle);continue}let r=this.handlers.get(t.type);if(!r){this.logger?.warn?.(`jobs.queue.scaleway_sqs.missing_handler`,{jobType:t.type,messageId:n.MessageId}),await this.deleteMessage(n.ReceiptHandle);continue}let i=new Date,a=parseInt(n.Attributes?.ApproximateReceiveCount??`1`,10),o={id:t.id,type:t.type,version:1,payload:t.payload,status:`pending`,priority:0,attempts:a,maxRetries:e.DEFAULT_RETRY_POLICY.maxRetries,createdAt:i,updatedAt:i};o.status=`running`,o.updatedAt=new Date;try{await r(o),o.status=`completed`,o.updatedAt=new Date,await this.deleteMessage(n.ReceiptHandle)}catch(e){o.status=`failed`,o.lastError=e instanceof Error?e.message:`Unknown job error`,o.updatedAt=new Date,this.logger?.error?.(`jobs.queue.scaleway_sqs.job_failed`,{jobType:o.type,jobId:o.id,error:e instanceof Error?e.message:String(e)})}}}catch(e){this.logger?.error?.(`jobs.queue.scaleway_sqs.poll_error`,{error:e instanceof Error?e.message:String(e)}),await this.sleep(5e3)}this.logger?.info?.(`jobs.queue.scaleway_sqs.stopped`,{queueUrl:this.queueUrl})}async deleteMessage(e){try{await this.sqs.send(new n({QueueUrl:this.queueUrl,ReceiptHandle:e}))}catch(e){this.logger?.warn?.(`jobs.queue.scaleway_sqs.delete_failed`,{error:e instanceof Error?e.message:String(e)})}}async sleep(e){await new Promise(t=>setTimeout(t,e))}};export{o as ScalewaySqsJobQueue};
|
package/dist/queue/types.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export { DEFAULT_RETRY_POLICY, calculateBackoff, defineJobType };
|
|
1
|
+
import{__reExport as e}from"../_virtual/rolldown_runtime.js";export*from"@lssm/lib.contracts/jobs/queue";var t={};import*as n from"@lssm/lib.contracts/jobs/queue";e(t,n);export{t as types_exports};
|