@lssm/lib.jobs 0.0.0-canary-20251217073102 → 0.0.0-canary-20251217083314
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 +42 -1
- package/dist/contracts/dist/capabilities/openbanking.js +88 -1
- package/dist/contracts/dist/client/index.js +5 -1
- package/dist/contracts/dist/client/react/feature-render.js +2 -1
- package/dist/contracts/dist/client/react/form-render.js +4 -1
- package/dist/contracts/dist/client/react/index.js +4 -1
- package/dist/contracts/dist/contract-registry/index.js +1 -1
- package/dist/contracts/dist/contract-registry/schemas.js +60 -1
- package/dist/contracts/dist/docs/PUBLISHING.docblock.js +16 -76
- package/dist/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -350
- package/dist/contracts/dist/docs/index.js +29 -1
- package/dist/contracts/dist/docs/presentations.js +71 -1
- package/dist/contracts/dist/docs/registry.js +44 -1
- package/dist/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -383
- package/dist/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -68
- package/dist/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -140
- package/dist/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -86
- package/dist/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -1
- package/dist/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +24 -2
- package/dist/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +21 -2
- package/dist/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -213
- package/dist/contracts/dist/docs/tech/llm/llm-integration.docblock.js +73 -5
- package/dist/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -1
- package/dist/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -1
- package/dist/contracts/dist/docs/tech/schema/README.docblock.js +20 -262
- package/dist/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -1
- package/dist/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +24 -2
- package/dist/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +23 -2
- package/dist/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +25 -16
- package/dist/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -1
- package/dist/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +22 -2
- package/dist/contracts/dist/docs/tech/studio/team-invitations.docblock.js +40 -36
- package/dist/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -1
- package/dist/contracts/dist/docs/tech/studio/workspaces.docblock.js +23 -2
- package/dist/contracts/dist/docs/tech/telemetry-ingest.docblock.js +36 -3
- package/dist/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -1
- package/dist/contracts/dist/docs/tech/vscode-extension.docblock.js +36 -3
- package/dist/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -1
- package/dist/contracts/dist/events.js +10 -1
- package/dist/contracts/dist/experiments/evaluator.js +1 -1
- package/dist/contracts/dist/index.js +71 -1
- package/dist/contracts/dist/install.js +2 -1
- package/dist/contracts/dist/integrations/contracts.js +377 -1
- package/dist/contracts/dist/integrations/index.js +18 -1
- package/dist/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -1
- package/dist/contracts/dist/integrations/openbanking/contracts/balances.js +159 -1
- package/dist/contracts/dist/integrations/openbanking/contracts/index.js +3 -1
- package/dist/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -1
- package/dist/contracts/dist/integrations/openbanking/models.js +242 -1
- package/dist/contracts/dist/integrations/openbanking/telemetry.js +13 -1
- package/dist/contracts/dist/integrations/providers/elevenlabs.js +52 -1
- package/dist/contracts/dist/integrations/providers/gcs-storage.js +75 -1
- package/dist/contracts/dist/integrations/providers/gmail.js +87 -1
- package/dist/contracts/dist/integrations/providers/google-calendar.js +66 -1
- package/dist/contracts/dist/integrations/providers/index.js +11 -1
- package/dist/contracts/dist/integrations/providers/mistral.js +68 -1
- package/dist/contracts/dist/integrations/providers/postmark.js +68 -1
- package/dist/contracts/dist/integrations/providers/powens.js +116 -1
- package/dist/contracts/dist/integrations/providers/qdrant.js +73 -1
- package/dist/contracts/dist/integrations/providers/registry.js +10 -1
- package/dist/contracts/dist/integrations/providers/stripe.js +83 -1
- package/dist/contracts/dist/integrations/providers/twilio-sms.js +61 -1
- package/dist/contracts/dist/jobs/queue.js +33 -1
- package/dist/contracts/dist/jsonschema.js +1 -1
- package/dist/contracts/dist/knowledge/contracts.js +306 -1
- package/dist/contracts/dist/knowledge/index.js +7 -1
- package/dist/contracts/dist/knowledge/spaces/email-threads.js +34 -1
- package/dist/contracts/dist/knowledge/spaces/financial-docs.js +34 -1
- package/dist/contracts/dist/knowledge/spaces/financial-overview.js +38 -1
- package/dist/contracts/dist/knowledge/spaces/index.js +6 -1
- package/dist/contracts/dist/knowledge/spaces/product-canon.js +34 -1
- package/dist/contracts/dist/knowledge/spaces/support-faq.js +37 -1
- package/dist/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -1
- package/dist/contracts/dist/llm/exporters.js +19 -1
- package/dist/contracts/dist/llm/index.js +2 -1
- package/dist/contracts/dist/llm/prompts.js +1 -1
- package/dist/contracts/dist/onboarding-base.js +196 -1
- package/dist/contracts/dist/openapi.js +1 -1
- package/dist/contracts/dist/ownership.js +21 -1
- package/dist/contracts/dist/presentations.js +1 -1
- package/dist/contracts/dist/presentations.v2.js +11 -1
- package/dist/contracts/dist/prompt.js +1 -1
- package/dist/contracts/dist/promptRegistry.js +1 -1
- package/dist/contracts/dist/regenerator/index.js +1 -1
- package/dist/contracts/dist/regenerator/service.js +6 -1
- package/dist/contracts/dist/registry.js +2 -1
- package/dist/contracts/dist/resources.js +1 -1
- package/dist/contracts/dist/schema/dist/EnumType.js +2 -1
- package/dist/contracts/dist/schema/dist/FieldType.js +49 -1
- package/dist/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -1
- package/dist/contracts/dist/schema/dist/SchemaModel.js +34 -1
- package/dist/contracts/dist/schema/dist/entity/defineEntity.js +1 -1
- package/dist/contracts/dist/schema/dist/entity/index.js +2 -1
- package/dist/contracts/dist/schema/dist/entity/types.js +1 -1
- package/dist/contracts/dist/schema/dist/index.js +6 -1
- package/dist/contracts/dist/server/graphql-pothos.js +6 -1
- package/dist/contracts/dist/server/index.js +8 -1
- package/dist/contracts/dist/server/mcp/createMcpServer.js +4 -1
- package/dist/contracts/dist/server/mcp/registerPresentations.js +2 -1
- package/dist/contracts/dist/server/mcp/registerPrompts.js +1 -1
- package/dist/contracts/dist/server/mcp/registerResources.js +2 -1
- package/dist/contracts/dist/server/mcp/registerTools.js +1 -1
- package/dist/contracts/dist/server/provider-mcp.js +1 -1
- package/dist/contracts/dist/server/rest-elysia.js +1 -1
- package/dist/contracts/dist/server/rest-express.js +1 -1
- package/dist/contracts/dist/server/rest-generic.js +1 -1
- package/dist/contracts/dist/server/rest-next-app.js +1 -1
- package/dist/contracts/dist/server/rest-next-pages.js +1 -1
- package/dist/contracts/dist/spec.js +34 -1
- package/dist/contracts/dist/telemetry/index.js +1 -1
- package/dist/contracts/dist/telemetry/tracker.js +1 -1
- package/dist/contracts/dist/tests/index.js +1 -1
- package/dist/contracts/dist/tests/runner.js +2 -1
- package/dist/contracts/dist/workflow/index.js +1 -1
- package/dist/contracts/dist/workflow/runner.js +1 -1
- package/dist/contracts/index.js +484 -1
- package/dist/entities/index.js +198 -1
- package/dist/events.js +303 -1
- package/dist/handlers/gmail-sync-handler.js +9 -1
- package/dist/handlers/index.js +12 -1
- package/dist/handlers/ping-job.d.ts +3 -3
- package/dist/handlers/ping-job.js +13 -1
- package/dist/handlers/storage-document-handler.js +14 -1
- package/dist/index.js +18 -1
- package/dist/jobs.feature.js +101 -1
- package/dist/queue/gcp-cloud-tasks.js +61 -1
- package/dist/queue/gcp-pubsub.js +47 -1
- package/dist/queue/index.js +9 -1
- package/dist/queue/memory-queue.js +140 -1
- package/dist/queue/register-defined-job.js +15 -1
- package/dist/queue/scaleway-sqs-queue.js +175 -1
- package/dist/queue/types.js +3 -1
- package/dist/scheduler/index.js +145 -1
- package/dist/schema/dist/EnumType.js +2 -1
- package/dist/schema/dist/FieldType.js +49 -1
- package/dist/schema/dist/ScalarTypeEnum.js +236 -1
- package/dist/schema/dist/SchemaModel.js +39 -1
- package/dist/schema/dist/entity/defineEntity.js +236 -1
- package/dist/schema/dist/entity/index.js +2 -1
- package/dist/schema/dist/entity/types.js +1 -1
- package/dist/schema/dist/index.js +6 -1
- package/package.json +7 -7
package/dist/jobs.feature.js
CHANGED
|
@@ -1 +1,101 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/jobs.feature.ts
|
|
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 +1,61 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { DEFAULT_RETRY_POLICY } from "../contracts/dist/jobs/queue.js";
|
|
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 };
|
package/dist/queue/gcp-pubsub.js
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { DEFAULT_RETRY_POLICY } from "../contracts/dist/jobs/queue.js";
|
|
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 };
|
package/dist/queue/index.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { DEFAULT_RETRY_POLICY, calculateBackoff, defineJobType } from "../contracts/dist/jobs/queue.js";
|
|
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 +1,140 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { DEFAULT_RETRY_POLICY, calculateBackoff } from "../contracts/dist/jobs/queue.js";
|
|
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 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/queue/register-defined-job.ts
|
|
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 +1,175 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { DEFAULT_RETRY_POLICY } from "../contracts/dist/jobs/queue.js";
|
|
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 };
|
package/dist/queue/types.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { DEFAULT_RETRY_POLICY, calculateBackoff, defineJobType } from "../contracts/dist/jobs/queue.js";
|
|
2
|
+
|
|
3
|
+
export { DEFAULT_RETRY_POLICY, calculateBackoff, defineJobType };
|