@lssm/lib.jobs 0.0.0-canary-20251217062943 → 0.0.0-canary-20251217072406
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.d.ts +138 -138
- package/dist/contracts/index.js +484 -1
- package/dist/entities/index.d.ts +116 -116
- 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 -6
|
@@ -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 };
|
package/dist/scheduler/index.js
CHANGED
|
@@ -1 +1,145 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/scheduler/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Parse a cron expression to get the next run time.
|
|
4
|
+
* Simple implementation supporting: minute hour day month weekday
|
|
5
|
+
*/
|
|
6
|
+
function getNextCronRun(cronExpression, after = /* @__PURE__ */ new Date()) {
|
|
7
|
+
try {
|
|
8
|
+
const parts = cronExpression.trim().split(/\s+/);
|
|
9
|
+
if (parts.length !== 5) {
|
|
10
|
+
console.warn(`Invalid cron expression: ${cronExpression}`);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const minute = parts[0];
|
|
14
|
+
const hour = parts[1];
|
|
15
|
+
const dayOfMonth = parts[2];
|
|
16
|
+
const month = parts[3];
|
|
17
|
+
const next = new Date(after);
|
|
18
|
+
next.setSeconds(0);
|
|
19
|
+
next.setMilliseconds(0);
|
|
20
|
+
if (minute && hour && minute !== "*" && hour !== "*" && dayOfMonth === "*" && month === "*") {
|
|
21
|
+
const targetMinute = Number.parseInt(minute, 10);
|
|
22
|
+
const targetHour = Number.parseInt(hour, 10);
|
|
23
|
+
next.setHours(targetHour, targetMinute, 0, 0);
|
|
24
|
+
if (next <= after) next.setDate(next.getDate() + 1);
|
|
25
|
+
return next;
|
|
26
|
+
}
|
|
27
|
+
next.setMinutes(next.getMinutes() + 1);
|
|
28
|
+
return next;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Job scheduler for recurring jobs.
|
|
35
|
+
*/
|
|
36
|
+
var JobScheduler = class {
|
|
37
|
+
schedules = /* @__PURE__ */ new Map();
|
|
38
|
+
timer;
|
|
39
|
+
checkIntervalMs;
|
|
40
|
+
constructor(queue, options = {}) {
|
|
41
|
+
this.queue = queue;
|
|
42
|
+
this.checkIntervalMs = options.checkIntervalMs ?? 6e4;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Add a scheduled job.
|
|
46
|
+
*/
|
|
47
|
+
schedule(config) {
|
|
48
|
+
const nextRun = config.enabled !== false ? getNextCronRun(config.cronExpression) : null;
|
|
49
|
+
this.schedules.set(config.name, {
|
|
50
|
+
...config,
|
|
51
|
+
enabled: config.enabled ?? true,
|
|
52
|
+
nextRun,
|
|
53
|
+
lastRun: null
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Remove a scheduled job.
|
|
58
|
+
*/
|
|
59
|
+
unschedule(name) {
|
|
60
|
+
return this.schedules.delete(name);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Enable a scheduled job.
|
|
64
|
+
*/
|
|
65
|
+
enable(name) {
|
|
66
|
+
const schedule = this.schedules.get(name);
|
|
67
|
+
if (!schedule) return false;
|
|
68
|
+
schedule.enabled = true;
|
|
69
|
+
schedule.nextRun = getNextCronRun(schedule.cronExpression);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Disable a scheduled job.
|
|
74
|
+
*/
|
|
75
|
+
disable(name) {
|
|
76
|
+
const schedule = this.schedules.get(name);
|
|
77
|
+
if (!schedule) return false;
|
|
78
|
+
schedule.enabled = false;
|
|
79
|
+
schedule.nextRun = null;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get all schedules.
|
|
84
|
+
*/
|
|
85
|
+
getSchedules() {
|
|
86
|
+
return Array.from(this.schedules.values());
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get a specific schedule.
|
|
90
|
+
*/
|
|
91
|
+
getSchedule(name) {
|
|
92
|
+
return this.schedules.get(name);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Start the scheduler.
|
|
96
|
+
*/
|
|
97
|
+
start() {
|
|
98
|
+
if (this.timer) return;
|
|
99
|
+
this.checkSchedules();
|
|
100
|
+
this.timer = setInterval(() => {
|
|
101
|
+
this.checkSchedules();
|
|
102
|
+
}, this.checkIntervalMs);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Stop the scheduler.
|
|
106
|
+
*/
|
|
107
|
+
stop() {
|
|
108
|
+
if (this.timer) {
|
|
109
|
+
clearInterval(this.timer);
|
|
110
|
+
this.timer = void 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check and enqueue due schedules.
|
|
115
|
+
*/
|
|
116
|
+
async checkSchedules() {
|
|
117
|
+
const now = /* @__PURE__ */ new Date();
|
|
118
|
+
for (const schedule of this.schedules.values()) {
|
|
119
|
+
if (!schedule.enabled || !schedule.nextRun) continue;
|
|
120
|
+
if (schedule.nextRun <= now) try {
|
|
121
|
+
const payload = typeof schedule.payload === "function" ? await schedule.payload() : schedule.payload;
|
|
122
|
+
await this.queue.enqueue(schedule.jobType, payload, schedule.options);
|
|
123
|
+
schedule.lastRun = now;
|
|
124
|
+
schedule.nextRun = getNextCronRun(schedule.cronExpression, now);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(`Failed to enqueue scheduled job ${schedule.name}:`, error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Create a job scheduler instance.
|
|
133
|
+
*/
|
|
134
|
+
function createScheduler(queue, options) {
|
|
135
|
+
return new JobScheduler(queue, options);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Helper to define a scheduled job configuration.
|
|
139
|
+
*/
|
|
140
|
+
function defineSchedule(config) {
|
|
141
|
+
return config;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
export { JobScheduler, createScheduler, defineSchedule };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"zod";
|
|
1
|
+
import "zod";
|
|
2
|
+
import "graphql";
|
|
@@ -1 +1,49 @@
|
|
|
1
|
-
import"zod";
|
|
1
|
+
import "zod";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
3
|
+
|
|
4
|
+
//#region ../schema/dist/FieldType.js
|
|
5
|
+
/**
|
|
6
|
+
* GraphQL scalar wrapper that carries zod and JSON Schema metadata.
|
|
7
|
+
*
|
|
8
|
+
* TInternal is the runtime representation; TExternal is the GraphQL output.
|
|
9
|
+
*/
|
|
10
|
+
var FieldType = class extends GraphQLScalarType {
|
|
11
|
+
zodSchema;
|
|
12
|
+
jsonSchemaDef;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super(config);
|
|
15
|
+
this.zodSchema = config.zod;
|
|
16
|
+
this.jsonSchemaDef = config.jsonSchema;
|
|
17
|
+
}
|
|
18
|
+
/** Return the attached zod schema for validation. */
|
|
19
|
+
getZod() {
|
|
20
|
+
return this.zodSchema;
|
|
21
|
+
}
|
|
22
|
+
/** GraphQL scalar instance usable by Pothos or vanilla GraphQL. */
|
|
23
|
+
getPothos() {
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/** Return the JSON Schema (evaluates factory if provided). */
|
|
27
|
+
getJson() {
|
|
28
|
+
return typeof this.jsonSchemaDef === "function" ? this.jsonSchemaDef() : this.jsonSchemaDef;
|
|
29
|
+
}
|
|
30
|
+
getJsonSchemaDef() {
|
|
31
|
+
return this.jsonSchemaDef;
|
|
32
|
+
}
|
|
33
|
+
getJsonSchema() {
|
|
34
|
+
const deepResolve = (v) => {
|
|
35
|
+
const value = typeof v === "function" ? v() : v;
|
|
36
|
+
if (Array.isArray(value)) return value.map((item) => deepResolve(item));
|
|
37
|
+
if (value && typeof value === "object") {
|
|
38
|
+
const obj = {};
|
|
39
|
+
for (const [k, val] of Object.entries(value)) obj[k] = deepResolve(val);
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
return deepResolve(this.getJson());
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { FieldType };
|