nvent 0.4.4 → 0.4.5
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/module.d.mts +3 -184
- package/dist/module.json +3 -3
- package/dist/module.mjs +133 -197
- package/dist/runtime/adapters/builtin/file-queue.d.ts +53 -0
- package/dist/runtime/adapters/builtin/file-queue.js +435 -0
- package/dist/runtime/adapters/builtin/file-store.d.ts +46 -0
- package/dist/runtime/adapters/builtin/file-store.js +225 -0
- package/dist/runtime/adapters/builtin/file-stream.d.ts +39 -0
- package/dist/runtime/adapters/builtin/file-stream.js +56 -0
- package/dist/runtime/adapters/builtin/index.d.ts +10 -0
- package/dist/runtime/adapters/builtin/index.js +5 -0
- package/dist/runtime/adapters/builtin/memory-queue.d.ts +52 -0
- package/dist/runtime/adapters/builtin/memory-queue.js +239 -0
- package/dist/runtime/adapters/builtin/memory-store.d.ts +57 -0
- package/dist/runtime/adapters/builtin/memory-store.js +263 -0
- package/dist/runtime/adapters/builtin/memory-stream.d.ts +21 -0
- package/dist/runtime/adapters/builtin/memory-stream.js +56 -0
- package/dist/runtime/adapters/factory.d.ts +31 -0
- package/dist/runtime/adapters/factory.js +100 -0
- package/dist/runtime/adapters/index.d.ts +8 -0
- package/dist/runtime/adapters/index.js +3 -0
- package/dist/runtime/adapters/interfaces/index.d.ts +11 -0
- package/dist/runtime/adapters/interfaces/index.js +3 -0
- package/dist/runtime/adapters/interfaces/queue.d.ts +150 -0
- package/dist/runtime/adapters/interfaces/store.d.ts +233 -0
- package/dist/runtime/adapters/interfaces/stream.d.ts +62 -0
- package/dist/runtime/adapters/registry.d.ts +85 -0
- package/dist/runtime/adapters/registry.js +161 -0
- package/dist/runtime/config/index.d.ts +29 -0
- package/dist/runtime/config/index.js +167 -0
- package/dist/runtime/config/types.d.ts +367 -0
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/events/types.d.ts +116 -0
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/stallDetector.d.ts +99 -0
- package/dist/runtime/events/utils/stallDetector.js +237 -0
- package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.d.ts +3 -8
- package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.js +119 -36
- package/dist/runtime/events/wiring/registry.d.ts +19 -0
- package/dist/runtime/events/wiring/registry.js +33 -0
- package/dist/runtime/events/wiring/stateWiring.d.ts +37 -0
- package/dist/runtime/events/wiring/stateWiring.js +92 -0
- package/dist/runtime/events/wiring/streamWiring.d.ts +32 -0
- package/dist/runtime/events/wiring/streamWiring.js +79 -0
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +16 -5
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.js +21 -0
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +12 -2
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +15 -4
- package/dist/runtime/server/api/_flows/[name]/schedule.post.js +11 -2
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +21 -16
- package/dist/runtime/server/api/_flows/[name]/schedules.get.js +21 -19
- package/dist/runtime/server/api/_flows/ws.js +43 -22
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +8 -3
- package/dist/runtime/server/api/_queues/[name]/job/index.get.js +12 -3
- package/dist/runtime/server/api/_queues/index.get.js +66 -23
- package/dist/runtime/server/api/_queues/ws.js +14 -4
- package/dist/runtime/server/plugins/00.adapters.d.ts +14 -0
- package/dist/runtime/server/plugins/00.adapters.js +69 -0
- package/dist/runtime/server/plugins/02.workers.js +45 -0
- package/dist/runtime/tsconfig.json +8 -0
- package/dist/runtime/utils/adapters.d.ts +66 -0
- package/dist/runtime/utils/adapters.js +51 -0
- package/dist/runtime/utils/defineFunction.d.ts +10 -0
- package/dist/runtime/{server-utils/utils/defineQueueWorker.js → utils/defineFunction.js} +4 -4
- package/dist/runtime/{server-utils/utils/defineQueueConfig.d.ts → utils/defineFunctionConfig.d.ts} +3 -3
- package/dist/runtime/utils/defineFunctionConfig.js +2 -0
- package/dist/runtime/utils/registerAdapter.d.ts +59 -0
- package/dist/runtime/utils/registerAdapter.js +13 -0
- package/dist/runtime/utils/useFlowEngine.d.ts +19 -0
- package/dist/runtime/utils/useFlowEngine.js +108 -0
- package/dist/runtime/{server-utils/utils → utils}/useNventLogger.js +2 -2
- package/dist/runtime/utils/useStreamTopics.d.ts +72 -0
- package/dist/runtime/utils/useStreamTopics.js +47 -0
- package/dist/runtime/{server-utils/worker/runner/node.d.ts → worker/node/runner.d.ts} +18 -2
- package/dist/runtime/{server-utils/worker/runner/node.js → worker/node/runner.js} +44 -17
- package/dist/types.d.mts +2 -2
- package/package.json +14 -44
- package/LICENSE +0 -21
- package/README.md +0 -389
- package/dist/runtime/app/assets/vueflow.css +0 -1
- package/dist/runtime/app/components/ConfirmDialog.d.vue.ts +0 -33
- package/dist/runtime/app/components/ConfirmDialog.vue +0 -121
- package/dist/runtime/app/components/ConfirmDialog.vue.d.ts +0 -33
- package/dist/runtime/app/components/FlowDiagram.d.vue.ts +0 -64
- package/dist/runtime/app/components/FlowDiagram.vue +0 -338
- package/dist/runtime/app/components/FlowDiagram.vue.d.ts +0 -64
- package/dist/runtime/app/components/FlowNodeCard.d.vue.ts +0 -29
- package/dist/runtime/app/components/FlowNodeCard.vue +0 -156
- package/dist/runtime/app/components/FlowNodeCard.vue.d.ts +0 -29
- package/dist/runtime/app/components/FlowRunOverview.d.vue.ts +0 -9
- package/dist/runtime/app/components/FlowRunOverview.vue +0 -291
- package/dist/runtime/app/components/FlowRunOverview.vue.d.ts +0 -9
- package/dist/runtime/app/components/FlowRunStatusBadge.d.vue.ts +0 -14
- package/dist/runtime/app/components/FlowRunStatusBadge.vue +0 -60
- package/dist/runtime/app/components/FlowRunStatusBadge.vue.d.ts +0 -14
- package/dist/runtime/app/components/FlowRunTimeline.d.vue.ts +0 -12
- package/dist/runtime/app/components/FlowRunTimeline.vue +0 -127
- package/dist/runtime/app/components/FlowRunTimeline.vue.d.ts +0 -12
- package/dist/runtime/app/components/FlowScheduleDialog.d.vue.ts +0 -16
- package/dist/runtime/app/components/FlowScheduleDialog.vue +0 -226
- package/dist/runtime/app/components/FlowScheduleDialog.vue.d.ts +0 -16
- package/dist/runtime/app/components/FlowSchedulesList.d.vue.ts +0 -12
- package/dist/runtime/app/components/FlowSchedulesList.vue +0 -99
- package/dist/runtime/app/components/FlowSchedulesList.vue.d.ts +0 -12
- package/dist/runtime/app/components/JobScheduling.d.vue.ts +0 -6
- package/dist/runtime/app/components/JobScheduling.vue +0 -203
- package/dist/runtime/app/components/JobScheduling.vue.d.ts +0 -6
- package/dist/runtime/app/components/ListItem.d.vue.ts +0 -23
- package/dist/runtime/app/components/ListItem.vue +0 -70
- package/dist/runtime/app/components/ListItem.vue.d.ts +0 -23
- package/dist/runtime/app/components/QueueConfigDetails.d.vue.ts +0 -45
- package/dist/runtime/app/components/QueueConfigDetails.vue +0 -412
- package/dist/runtime/app/components/QueueConfigDetails.vue.d.ts +0 -45
- package/dist/runtime/app/components/StatCounter.d.vue.ts +0 -9
- package/dist/runtime/app/components/StatCounter.vue +0 -25
- package/dist/runtime/app/components/StatCounter.vue.d.ts +0 -9
- package/dist/runtime/app/components/TimelineList.d.vue.ts +0 -7
- package/dist/runtime/app/components/TimelineList.vue +0 -210
- package/dist/runtime/app/components/TimelineList.vue.d.ts +0 -7
- package/dist/runtime/app/components/nhealth/component-router.d.vue.ts +0 -46
- package/dist/runtime/app/components/nhealth/component-router.vue +0 -26
- package/dist/runtime/app/components/nhealth/component-router.vue.d.ts +0 -46
- package/dist/runtime/app/components/nhealth/component-shell.d.vue.ts +0 -24
- package/dist/runtime/app/components/nhealth/component-shell.vue +0 -89
- package/dist/runtime/app/components/nhealth/component-shell.vue.d.ts +0 -24
- package/dist/runtime/app/composables/useAnalyzedFlows.d.ts +0 -14
- package/dist/runtime/app/composables/useAnalyzedFlows.js +0 -8
- package/dist/runtime/app/composables/useComponentRouter.d.ts +0 -38
- package/dist/runtime/app/composables/useComponentRouter.js +0 -240
- package/dist/runtime/app/composables/useFlowRunTimeline.d.ts +0 -80
- package/dist/runtime/app/composables/useFlowRunTimeline.js +0 -68
- package/dist/runtime/app/composables/useFlowRuns.d.ts +0 -18
- package/dist/runtime/app/composables/useFlowRuns.js +0 -32
- package/dist/runtime/app/composables/useFlowRunsInfinite.d.ts +0 -24
- package/dist/runtime/app/composables/useFlowRunsInfinite.js +0 -123
- package/dist/runtime/app/composables/useFlowRunsPolling.d.ts +0 -9
- package/dist/runtime/app/composables/useFlowRunsPolling.js +0 -33
- package/dist/runtime/app/composables/useFlowState.d.ts +0 -125
- package/dist/runtime/app/composables/useFlowState.js +0 -211
- package/dist/runtime/app/composables/useFlowWebSocket.d.ts +0 -27
- package/dist/runtime/app/composables/useFlowWebSocket.js +0 -205
- package/dist/runtime/app/composables/useFlowsNavigation.d.ts +0 -10
- package/dist/runtime/app/composables/useFlowsNavigation.js +0 -58
- package/dist/runtime/app/composables/useQueueJobs.d.ts +0 -26
- package/dist/runtime/app/composables/useQueueJobs.js +0 -20
- package/dist/runtime/app/composables/useQueueUpdates.d.ts +0 -26
- package/dist/runtime/app/composables/useQueueUpdates.js +0 -122
- package/dist/runtime/app/composables/useQueues.d.ts +0 -45
- package/dist/runtime/app/composables/useQueues.js +0 -26
- package/dist/runtime/app/composables/useQueuesLive.d.ts +0 -19
- package/dist/runtime/app/composables/useQueuesLive.js +0 -143
- package/dist/runtime/app/pages/flows/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/flows/index.vue +0 -645
- package/dist/runtime/app/pages/flows/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/index.vue +0 -34
- package/dist/runtime/app/pages/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/index.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/index.vue +0 -229
- package/dist/runtime/app/pages/queues/index.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/job.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/job.vue +0 -262
- package/dist/runtime/app/pages/queues/job.vue.d.ts +0 -3
- package/dist/runtime/app/pages/queues/jobs.d.vue.ts +0 -3
- package/dist/runtime/app/pages/queues/jobs.vue +0 -291
- package/dist/runtime/app/pages/queues/jobs.vue.d.ts +0 -3
- package/dist/runtime/app/plugins/vueflow.client.d.ts +0 -2
- package/dist/runtime/app/plugins/vueflow.client.js +0 -11
- package/dist/runtime/constants.d.ts +0 -11
- package/dist/runtime/constants.js +0 -11
- package/dist/runtime/schema.d.ts +0 -37
- package/dist/runtime/schema.js +0 -20
- package/dist/runtime/server/plugins/00.event-store.d.ts +0 -13
- package/dist/runtime/server/plugins/00.event-store.js +0 -16
- package/dist/runtime/server/plugins/flow-management.d.ts +0 -13
- package/dist/runtime/server/plugins/flow-management.js +0 -65
- package/dist/runtime/server/plugins/queue-management.js +0 -27
- package/dist/runtime/server/plugins/state-cleanup.d.ts +0 -11
- package/dist/runtime/server/plugins/state-cleanup.js +0 -93
- package/dist/runtime/server/plugins/worker-management.js +0 -33
- package/dist/runtime/server/tsconfig.json +0 -3
- package/dist/runtime/server-utils/events/adapters/fileAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/fileAdapter.js +0 -382
- package/dist/runtime/server-utils/events/adapters/memoryAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/memoryAdapter.js +0 -171
- package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.d.ts +0 -2
- package/dist/runtime/server-utils/events/adapters/redis/redisAdapter.js +0 -348
- package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.d.ts +0 -30
- package/dist/runtime/server-utils/events/adapters/redis/redisPubSubGateway.js +0 -82
- package/dist/runtime/server-utils/events/eventStoreFactory.d.ts +0 -19
- package/dist/runtime/server-utils/events/eventStoreFactory.js +0 -44
- package/dist/runtime/server-utils/events/streamNames.d.ts +0 -17
- package/dist/runtime/server-utils/events/streamNames.js +0 -17
- package/dist/runtime/server-utils/events/types.d.ts +0 -63
- package/dist/runtime/server-utils/events/wiring/registry.d.ts +0 -10
- package/dist/runtime/server-utils/events/wiring/registry.js +0 -24
- package/dist/runtime/server-utils/queue/adapters/bullmq.d.ts +0 -18
- package/dist/runtime/server-utils/queue/adapters/bullmq.js +0 -164
- package/dist/runtime/server-utils/queue/queueFactory.d.ts +0 -3
- package/dist/runtime/server-utils/queue/queueFactory.js +0 -10
- package/dist/runtime/server-utils/queue/types.d.ts +0 -47
- package/dist/runtime/server-utils/state/adapters/redis.d.ts +0 -2
- package/dist/runtime/server-utils/state/adapters/redis.js +0 -42
- package/dist/runtime/server-utils/state/stateFactory.d.ts +0 -3
- package/dist/runtime/server-utils/state/stateFactory.js +0 -17
- package/dist/runtime/server-utils/state/types.d.ts +0 -23
- package/dist/runtime/server-utils/utils/defineQueueConfig.js +0 -2
- package/dist/runtime/server-utils/utils/defineQueueWorker.d.ts +0 -10
- package/dist/runtime/server-utils/utils/useEventStore.d.ts +0 -20
- package/dist/runtime/server-utils/utils/useEventStore.js +0 -119
- package/dist/runtime/server-utils/utils/useFlowEngine.d.ts +0 -9
- package/dist/runtime/server-utils/utils/useFlowEngine.js +0 -44
- package/dist/runtime/server-utils/utils/useLogs.d.ts +0 -41
- package/dist/runtime/server-utils/utils/useLogs.js +0 -74
- package/dist/runtime/server-utils/utils/useQueue.d.ts +0 -31
- package/dist/runtime/server-utils/utils/useQueue.js +0 -24
- package/dist/runtime/server-utils/worker/adapter.d.ts +0 -4
- package/dist/runtime/server-utils/worker/adapter.js +0 -66
- package/dist/runtime/types.d.ts +0 -132
- /package/dist/runtime/{server-utils/events/types.js → adapters/interfaces/queue.js} +0 -0
- /package/dist/runtime/{server-utils/queue/types.js → adapters/interfaces/store.js} +0 -0
- /package/dist/runtime/{server-utils/state/types.js → adapters/interfaces/stream.js} +0 -0
- /package/dist/runtime/{server-utils/events → events}/eventBus.d.ts +0 -0
- /package/dist/runtime/{server-utils/events → events}/eventBus.js +0 -0
- /package/dist/runtime/server/{plugins/queue-management.d.ts → api/_flows/[name]/runs/[runId]/cancel.post.d.ts} +0 -0
- /package/dist/runtime/server/plugins/{00.ws-lifecycle.d.ts → 01.ws-lifecycle.d.ts} +0 -0
- /package/dist/runtime/server/plugins/{00.ws-lifecycle.js → 01.ws-lifecycle.js} +0 -0
- /package/dist/runtime/server/plugins/{worker-management.d.ts → 02.workers.d.ts} +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/useEventManager.d.ts +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/useEventManager.js +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/useNventLogger.d.ts +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/wsPeerManager.d.ts +0 -0
- /package/dist/runtime/{server-utils/utils → utils}/wsPeerManager.js +0 -0
- /package/dist/runtime/{python → worker/python}/get_config.py +0 -0
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { Queue, QueueEvents } from "bullmq";
|
|
2
|
-
import defu from "defu";
|
|
3
|
-
import { useRuntimeConfig, $useQueueRegistry, useEventManager, useNventLogger } from "#imports";
|
|
4
|
-
export class BullMQProvider {
|
|
5
|
-
queues = /* @__PURE__ */ new Map();
|
|
6
|
-
logger = useNventLogger("bullmq-adapter");
|
|
7
|
-
async init() {
|
|
8
|
-
}
|
|
9
|
-
ensureQueue(name) {
|
|
10
|
-
let cached = this.queues.get(name);
|
|
11
|
-
if (cached) return cached;
|
|
12
|
-
const { publishBus } = useEventManager();
|
|
13
|
-
const rc = useRuntimeConfig();
|
|
14
|
-
const connection = rc.queue?.queue?.redis;
|
|
15
|
-
let queueDefaults = void 0;
|
|
16
|
-
let prefix;
|
|
17
|
-
let limiter = void 0;
|
|
18
|
-
try {
|
|
19
|
-
const registry = $useQueueRegistry();
|
|
20
|
-
if (registry && Array.isArray(registry.workers)) {
|
|
21
|
-
const w = registry.workers.find((w2) => w2?.queue?.name === name);
|
|
22
|
-
if (w?.queue) {
|
|
23
|
-
queueDefaults = w.queue.defaultJobOptions;
|
|
24
|
-
prefix = w.queue.prefix;
|
|
25
|
-
limiter = w.queue.limiter;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
}
|
|
30
|
-
const queueOpts = { connection, prefix, defaultJobOptions: queueDefaults };
|
|
31
|
-
if (limiter) {
|
|
32
|
-
queueOpts.limiter = {
|
|
33
|
-
max: limiter.max,
|
|
34
|
-
duration: limiter.duration,
|
|
35
|
-
groupKey: limiter.groupKey
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const queue = new Queue(name, queueOpts);
|
|
39
|
-
const events = new QueueEvents(name, { connection, prefix });
|
|
40
|
-
events.setMaxListeners(50);
|
|
41
|
-
cached = { queue, events, wired: false, defaults: queueDefaults };
|
|
42
|
-
this.queues.set(name, cached);
|
|
43
|
-
const forward = async (kind, payload) => {
|
|
44
|
-
const jobId = payload?.jobId || "unknown";
|
|
45
|
-
let runId = "";
|
|
46
|
-
try {
|
|
47
|
-
if (jobId && jobId !== "unknown") {
|
|
48
|
-
const job = await queue.getJob(jobId);
|
|
49
|
-
if (job?.data?.flowId) {
|
|
50
|
-
runId = job.data.flowId;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} catch {
|
|
54
|
-
}
|
|
55
|
-
const rec = {
|
|
56
|
-
type: `job.${kind}`,
|
|
57
|
-
runId,
|
|
58
|
-
data: { ...payload, queue: name, jobId }
|
|
59
|
-
};
|
|
60
|
-
await publishBus(rec);
|
|
61
|
-
};
|
|
62
|
-
for (const ev of ["waiting", "active", "progress", "completed", "failed", "delayed"]) {
|
|
63
|
-
events.on(ev, (p) => {
|
|
64
|
-
void forward(ev, p);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
cached.wired = true;
|
|
68
|
-
return cached;
|
|
69
|
-
}
|
|
70
|
-
async enqueue(queueName, job) {
|
|
71
|
-
const { queue, defaults } = this.ensureQueue(queueName);
|
|
72
|
-
const opts = defu(job.opts || {}, defaults || {});
|
|
73
|
-
const bullJob = await queue.add(job.name, job.data, opts);
|
|
74
|
-
return bullJob.id;
|
|
75
|
-
}
|
|
76
|
-
async schedule(queueName, job, opts) {
|
|
77
|
-
const { queue, defaults } = this.ensureQueue(queueName);
|
|
78
|
-
const jobsOpts = defu({ ...job.opts }, defaults || {});
|
|
79
|
-
if (opts?.delay) jobsOpts.delay = opts.delay;
|
|
80
|
-
if (opts?.cron) jobsOpts.repeat = { pattern: opts.cron };
|
|
81
|
-
const bullJob = await queue.add(job.name, job.data, jobsOpts);
|
|
82
|
-
return bullJob.id;
|
|
83
|
-
}
|
|
84
|
-
async getJob(queueName, id) {
|
|
85
|
-
const { queue } = this.ensureQueue(queueName);
|
|
86
|
-
const j = await queue.getJob(id);
|
|
87
|
-
if (!j) return null;
|
|
88
|
-
return await this.toJob(j);
|
|
89
|
-
}
|
|
90
|
-
async getJobs(queueName, _q) {
|
|
91
|
-
const { queue } = this.ensureQueue(queueName);
|
|
92
|
-
const states = _q?.state && _q.state.length > 0 ? _q.state : ["waiting", "active", "completed", "failed", "delayed", "paused"];
|
|
93
|
-
const limit = _q?.limit || 1e3;
|
|
94
|
-
const jobs = await queue.getJobs(states, 0, limit - 1);
|
|
95
|
-
return await Promise.all(jobs.map((j) => this.toJob(j)));
|
|
96
|
-
}
|
|
97
|
-
on(queueName, event, cb) {
|
|
98
|
-
const { events } = this.ensureQueue(queueName);
|
|
99
|
-
const handler = (payload) => cb(payload);
|
|
100
|
-
events.on(event, handler);
|
|
101
|
-
return () => {
|
|
102
|
-
events.off(event, handler);
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
async isPaused(queueName) {
|
|
106
|
-
const { queue } = this.ensureQueue(queueName);
|
|
107
|
-
return await queue.isPaused();
|
|
108
|
-
}
|
|
109
|
-
async getJobCounts(queueName) {
|
|
110
|
-
const { queue } = this.ensureQueue(queueName);
|
|
111
|
-
const counts = await queue.getJobCounts("waiting", "active", "completed", "failed", "delayed", "paused");
|
|
112
|
-
return {
|
|
113
|
-
active: counts.active || 0,
|
|
114
|
-
completed: counts.completed || 0,
|
|
115
|
-
failed: counts.failed || 0,
|
|
116
|
-
delayed: counts.delayed || 0,
|
|
117
|
-
waiting: counts.waiting || 0,
|
|
118
|
-
paused: counts.paused || 0
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
async pause(queueName) {
|
|
122
|
-
const { queue } = this.ensureQueue(queueName);
|
|
123
|
-
await queue.pause();
|
|
124
|
-
}
|
|
125
|
-
async resume(queueName) {
|
|
126
|
-
const { queue } = this.ensureQueue(queueName);
|
|
127
|
-
await queue.resume();
|
|
128
|
-
}
|
|
129
|
-
async close() {
|
|
130
|
-
const closePromises = [];
|
|
131
|
-
for (const [queueName, { queue, events }] of this.queues.entries()) {
|
|
132
|
-
closePromises.push(
|
|
133
|
-
queue.close().catch((err) => {
|
|
134
|
-
if (err.code !== "EPIPE" && !err.message?.includes("Connection is closed")) {
|
|
135
|
-
this.logger.warn("Error closing queue", { queueName, error: err });
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
closePromises.push(
|
|
140
|
-
events.close().catch((err) => {
|
|
141
|
-
if (err.code !== "EPIPE" && !err.message?.includes("Connection is closed")) {
|
|
142
|
-
this.logger.warn("Error closing events for queue", { queueName, error: err });
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
await Promise.allSettled(closePromises);
|
|
148
|
-
this.queues.clear();
|
|
149
|
-
}
|
|
150
|
-
async toJob(j) {
|
|
151
|
-
const state = await j.getState();
|
|
152
|
-
return {
|
|
153
|
-
id: j.id,
|
|
154
|
-
name: j.name,
|
|
155
|
-
data: j.data,
|
|
156
|
-
returnvalue: j.returnvalue,
|
|
157
|
-
failedReason: j.failedReason,
|
|
158
|
-
state,
|
|
159
|
-
timestamp: j.timestamp,
|
|
160
|
-
processedOn: j.processedOn,
|
|
161
|
-
finishedOn: j.finishedOn
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export type JobCounts = {
|
|
2
|
-
active: number;
|
|
3
|
-
completed: number;
|
|
4
|
-
failed: number;
|
|
5
|
-
delayed: number;
|
|
6
|
-
waiting: number;
|
|
7
|
-
paused: number;
|
|
8
|
-
};
|
|
9
|
-
export type QueueEvent = 'added' | 'waiting' | 'active' | 'progress' | 'completed' | 'failed' | 'paused' | 'resumed';
|
|
10
|
-
export interface JobInput {
|
|
11
|
-
name: string;
|
|
12
|
-
data: any;
|
|
13
|
-
opts?: Record<string, any>;
|
|
14
|
-
}
|
|
15
|
-
export interface Job {
|
|
16
|
-
id: string;
|
|
17
|
-
name: string;
|
|
18
|
-
data: any;
|
|
19
|
-
state?: 'waiting' | 'active' | 'completed' | 'failed' | 'delayed' | 'paused';
|
|
20
|
-
returnvalue?: any;
|
|
21
|
-
failedReason?: string;
|
|
22
|
-
timestamp?: number;
|
|
23
|
-
processedOn?: number;
|
|
24
|
-
finishedOn?: number;
|
|
25
|
-
}
|
|
26
|
-
export interface JobsQuery {
|
|
27
|
-
state?: Array<Job['state']>;
|
|
28
|
-
limit?: number;
|
|
29
|
-
cursor?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface ScheduleOptions {
|
|
32
|
-
delay?: number;
|
|
33
|
-
cron?: string;
|
|
34
|
-
}
|
|
35
|
-
export interface QueueProvider {
|
|
36
|
-
init(): Promise<void>;
|
|
37
|
-
enqueue(queue: string, job: JobInput): Promise<string>;
|
|
38
|
-
schedule(queue: string, job: JobInput, opts?: ScheduleOptions): Promise<string>;
|
|
39
|
-
getJob(queue: string, id: string): Promise<Job | null>;
|
|
40
|
-
getJobs(queue: string, q?: JobsQuery): Promise<Job[]>;
|
|
41
|
-
on(queue: string, event: QueueEvent, cb: (p: any) => void): () => void;
|
|
42
|
-
getJobCounts?(queue: string): Promise<Record<string, number>>;
|
|
43
|
-
isPaused?(queue: string): Promise<boolean>;
|
|
44
|
-
pause(queue: string): Promise<void>;
|
|
45
|
-
resume(queue: string): Promise<void>;
|
|
46
|
-
close(): Promise<void>;
|
|
47
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useStorage, useRuntimeConfig } from "#imports";
|
|
2
|
-
function nsKey(ns, key) {
|
|
3
|
-
if (!key) return ns;
|
|
4
|
-
return key.startsWith(ns + ":") ? key : `${ns}:${key}`;
|
|
5
|
-
}
|
|
6
|
-
export function createRedisStateProvider(namespace) {
|
|
7
|
-
const storage = useStorage("redis");
|
|
8
|
-
const ns = namespace || useRuntimeConfig()?.queue?.state?.namespace || "nq";
|
|
9
|
-
return {
|
|
10
|
-
async get(key) {
|
|
11
|
-
return storage.getItem(nsKey(ns, key));
|
|
12
|
-
},
|
|
13
|
-
async set(key, value, opts) {
|
|
14
|
-
await storage.setItem(nsKey(ns, key), value, { ttl: opts?.ttl });
|
|
15
|
-
},
|
|
16
|
-
async delete(key) {
|
|
17
|
-
await storage.removeItem(nsKey(ns, key));
|
|
18
|
-
},
|
|
19
|
-
async list(prefix, opts) {
|
|
20
|
-
const base = nsKey(ns, prefix);
|
|
21
|
-
const keys = await storage.getKeys(base);
|
|
22
|
-
const filtered = keys.filter((k) => k.startsWith(base)).slice(0, opts?.limit || keys.length);
|
|
23
|
-
return { keys: filtered };
|
|
24
|
-
},
|
|
25
|
-
async patch(key, updater, opts) {
|
|
26
|
-
const retries = Math.max(0, opts?.retries ?? 3);
|
|
27
|
-
const k = nsKey(ns, key);
|
|
28
|
-
let lastErr;
|
|
29
|
-
for (let i = 0; i <= retries; i++) {
|
|
30
|
-
try {
|
|
31
|
-
const prev = await storage.getItem(k);
|
|
32
|
-
const next = updater(prev);
|
|
33
|
-
await storage.setItem(k, next);
|
|
34
|
-
return next;
|
|
35
|
-
} catch (err) {
|
|
36
|
-
lastErr = err;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
throw lastErr || new Error("patch failed");
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#imports";
|
|
2
|
-
import { createRedisStateProvider } from "./adapters/redis.js";
|
|
3
|
-
let currentStateProvider = null;
|
|
4
|
-
export function getStateProvider() {
|
|
5
|
-
if (currentStateProvider) return currentStateProvider;
|
|
6
|
-
const rc = useRuntimeConfig();
|
|
7
|
-
const adapter = rc?.queue?.state?.adapter || "redis";
|
|
8
|
-
const ns = rc?.queue?.state?.namespace || "nq";
|
|
9
|
-
if (adapter === "redis") {
|
|
10
|
-
currentStateProvider = createRedisStateProvider(ns);
|
|
11
|
-
return currentStateProvider;
|
|
12
|
-
}
|
|
13
|
-
throw new Error(`[nuxt-queue] Unsupported StateProvider: ${adapter}`);
|
|
14
|
-
}
|
|
15
|
-
export function setStateProvider(p) {
|
|
16
|
-
currentStateProvider = p;
|
|
17
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface StateProvider {
|
|
2
|
-
get<T = any>(key: string): Promise<T | null>;
|
|
3
|
-
set<T = any>(key: string, value: T, opts?: {
|
|
4
|
-
ttl?: number;
|
|
5
|
-
}): Promise<void>;
|
|
6
|
-
delete(key: string): Promise<void>;
|
|
7
|
-
list(prefix: string, opts?: {
|
|
8
|
-
limit?: number;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
keys: string[];
|
|
11
|
-
}>;
|
|
12
|
-
patch<T = any>(key: string, updater: (prev: T | null) => T, opts?: {
|
|
13
|
-
retries?: number;
|
|
14
|
-
}): Promise<T>;
|
|
15
|
-
}
|
|
16
|
-
export interface StorageLike {
|
|
17
|
-
getItem<T = any>(key: string): Promise<T | null>;
|
|
18
|
-
setItem<T = any>(key: string, value: T, opts?: {
|
|
19
|
-
ttl?: number;
|
|
20
|
-
}): Promise<void>;
|
|
21
|
-
removeItem(key: string): Promise<void>;
|
|
22
|
-
getKeys(base?: string): Promise<string[]>;
|
|
23
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useFlowEngine, useQueue } from '#imports';
|
|
2
|
-
import type { RunContext, NodeHandler } from '../worker/runner/node.js';
|
|
3
|
-
export type ExtendedRunContext = RunContext & {
|
|
4
|
-
provider: ReturnType<typeof useQueue>;
|
|
5
|
-
flow: ReturnType<typeof useFlowEngine>;
|
|
6
|
-
registry: any;
|
|
7
|
-
};
|
|
8
|
-
export type DefineQueueWorker = (handler: (input: any, ctx: ExtendedRunContext) => Promise<any>) => NodeHandler;
|
|
9
|
-
export declare const defineQueueWorker: DefineQueueWorker;
|
|
10
|
-
export default defineQueueWorker;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { EventReadOptions } from '../events/types.js';
|
|
2
|
-
import type { EventRecord } from '../types.js';
|
|
3
|
-
export declare function useEventStore(): {
|
|
4
|
-
names: () => import("../events/streamNames.js").StreamNames;
|
|
5
|
-
read: (stream: string, opts?: EventReadOptions) => Promise<EventRecord[]>;
|
|
6
|
-
indexAdd: (key: string, id: string, score: number, metadata?: Record<string, any>) => Promise<void>;
|
|
7
|
-
indexGet: (key: string, id: string) => Promise<import("../events/types.js").IndexEntry | null>;
|
|
8
|
-
indexUpdate: (key: string, id: string, metadata: Record<string, any>) => Promise<boolean>;
|
|
9
|
-
indexUpdateWithRetry: (key: string, id: string, metadata: Record<string, any>, maxRetries?: number) => Promise<void>;
|
|
10
|
-
indexIncrement: (key: string, id: string, field: string, increment?: number) => Promise<number>;
|
|
11
|
-
indexRead: (key: string, opts?: {
|
|
12
|
-
offset?: number;
|
|
13
|
-
limit?: number;
|
|
14
|
-
}) => Promise<import("../events/types.js").IndexEntry[]>;
|
|
15
|
-
deleteStream: (subject: string) => Promise<void>;
|
|
16
|
-
deleteByPattern: (pattern: string) => Promise<number>;
|
|
17
|
-
deleteIndex: (key: string) => Promise<void>;
|
|
18
|
-
subscribe: (stream: string, handler: (e: EventRecord) => void) => () => void;
|
|
19
|
-
adapter: import("../events/types.js").EventStoreAdapter;
|
|
20
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { getEventStoreFactory } from "../events/eventStoreFactory.js";
|
|
2
|
-
import { useNventLogger } from "#imports";
|
|
3
|
-
export function useEventStore() {
|
|
4
|
-
const logger = useNventLogger("event-store");
|
|
5
|
-
const factory = getEventStoreFactory();
|
|
6
|
-
async function read(stream, opts) {
|
|
7
|
-
return await factory.adapter.read(stream, opts);
|
|
8
|
-
}
|
|
9
|
-
async function indexAdd(key, id, score, metadata) {
|
|
10
|
-
if (!factory.adapter.indexAdd) {
|
|
11
|
-
throw new Error("Current adapter does not support indexAdd");
|
|
12
|
-
}
|
|
13
|
-
return await factory.adapter.indexAdd(key, id, score, metadata);
|
|
14
|
-
}
|
|
15
|
-
async function indexGet(key, id) {
|
|
16
|
-
if (!factory.adapter.indexGet) {
|
|
17
|
-
throw new Error("Current adapter does not support indexGet");
|
|
18
|
-
}
|
|
19
|
-
return await factory.adapter.indexGet(key, id);
|
|
20
|
-
}
|
|
21
|
-
async function indexUpdate(key, id, metadata) {
|
|
22
|
-
if (!factory.adapter.indexUpdate) {
|
|
23
|
-
throw new Error("Current adapter does not support indexUpdate");
|
|
24
|
-
}
|
|
25
|
-
return await factory.adapter.indexUpdate(key, id, metadata);
|
|
26
|
-
}
|
|
27
|
-
async function indexUpdateWithRetry(key, id, metadata, maxRetries) {
|
|
28
|
-
if (!factory.adapter.indexUpdateWithRetry) {
|
|
29
|
-
throw new Error("Current adapter does not support indexUpdateWithRetry");
|
|
30
|
-
}
|
|
31
|
-
return await factory.adapter.indexUpdateWithRetry(key, id, metadata, maxRetries);
|
|
32
|
-
}
|
|
33
|
-
async function indexIncrement(key, id, field, increment) {
|
|
34
|
-
if (!factory.adapter.indexIncrement) {
|
|
35
|
-
throw new Error("Current adapter does not support indexIncrement");
|
|
36
|
-
}
|
|
37
|
-
return await factory.adapter.indexIncrement(key, id, field, increment);
|
|
38
|
-
}
|
|
39
|
-
async function indexRead(key, opts) {
|
|
40
|
-
if (!factory.adapter.indexRead) {
|
|
41
|
-
throw new Error("Current adapter does not support indexRead");
|
|
42
|
-
}
|
|
43
|
-
return await factory.adapter.indexRead(key, opts);
|
|
44
|
-
}
|
|
45
|
-
async function deleteStream(subject) {
|
|
46
|
-
if (!factory.adapter.deleteStream) {
|
|
47
|
-
throw new Error("Current adapter does not support deleteStream");
|
|
48
|
-
}
|
|
49
|
-
return await factory.adapter.deleteStream(subject);
|
|
50
|
-
}
|
|
51
|
-
async function deleteByPattern(pattern) {
|
|
52
|
-
if (!factory.adapter.deleteByPattern) {
|
|
53
|
-
throw new Error("Current adapter does not support deleteByPattern");
|
|
54
|
-
}
|
|
55
|
-
return await factory.adapter.deleteByPattern(pattern);
|
|
56
|
-
}
|
|
57
|
-
async function deleteIndex(key) {
|
|
58
|
-
if (!factory.adapter.deleteIndex) {
|
|
59
|
-
throw new Error("Current adapter does not support deleteIndex");
|
|
60
|
-
}
|
|
61
|
-
return await factory.adapter.deleteIndex(key);
|
|
62
|
-
}
|
|
63
|
-
function names() {
|
|
64
|
-
return factory.names;
|
|
65
|
-
}
|
|
66
|
-
function subscribe(stream, handler) {
|
|
67
|
-
logger.debug("Subscribing to stream", { stream });
|
|
68
|
-
let sub = null;
|
|
69
|
-
let active = true;
|
|
70
|
-
(async () => {
|
|
71
|
-
try {
|
|
72
|
-
sub = await factory.adapter.subscribe(stream, (e) => {
|
|
73
|
-
logger.debug("Event received", { stream, id: e?.id, type: e?.type });
|
|
74
|
-
handler(e);
|
|
75
|
-
});
|
|
76
|
-
logger.debug("Subscription active", { stream });
|
|
77
|
-
} catch (err) {
|
|
78
|
-
logger.error("Subscription error", { stream, error: err });
|
|
79
|
-
}
|
|
80
|
-
if (!active && sub) {
|
|
81
|
-
try {
|
|
82
|
-
sub.unsubscribe();
|
|
83
|
-
} catch {
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
})();
|
|
87
|
-
return () => {
|
|
88
|
-
active = false;
|
|
89
|
-
if (sub) {
|
|
90
|
-
try {
|
|
91
|
-
sub.unsubscribe();
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
sub = null;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
// names
|
|
100
|
-
names,
|
|
101
|
-
// read from canonical streams
|
|
102
|
-
read,
|
|
103
|
-
// sorted set index operations
|
|
104
|
-
indexAdd,
|
|
105
|
-
indexGet,
|
|
106
|
-
indexUpdate,
|
|
107
|
-
indexUpdateWithRetry,
|
|
108
|
-
indexIncrement,
|
|
109
|
-
indexRead,
|
|
110
|
-
// deletion operations
|
|
111
|
-
deleteStream,
|
|
112
|
-
deleteByPattern,
|
|
113
|
-
deleteIndex,
|
|
114
|
-
// subscribe to canonical stream events via the adapter (Store Bus)
|
|
115
|
-
subscribe,
|
|
116
|
-
// expose adapter if advanced usage is needed
|
|
117
|
-
adapter: factory.adapter
|
|
118
|
-
};
|
|
119
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const useFlowEngine: () => {
|
|
2
|
-
startFlow: (flowName: string, payload?: any) => Promise<{
|
|
3
|
-
id: any;
|
|
4
|
-
queue: any;
|
|
5
|
-
step: any;
|
|
6
|
-
flowId: `${string}-${string}-${string}-${string}-${string}`;
|
|
7
|
-
}>;
|
|
8
|
-
emit: (trigger: string, payload?: any) => Promise<never[]>;
|
|
9
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { $useQueueRegistry, useQueue, useEventManager, useNventLogger } from "#imports";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
export const useFlowEngine = () => {
|
|
4
|
-
const registry = $useQueueRegistry();
|
|
5
|
-
const queueAdapter = useQueue();
|
|
6
|
-
const eventsManager = useEventManager();
|
|
7
|
-
const logger = useNventLogger("flow-engine");
|
|
8
|
-
const startFlow = async (flowName, payload = {}) => {
|
|
9
|
-
const flow = registry?.flows?.[flowName];
|
|
10
|
-
if (!flow || !flow.entry) throw new Error("Flow not found");
|
|
11
|
-
const queueName = typeof flow.entry.queue === "string" ? flow.entry.queue : flow.entry.queue?.name || flow.entry.queue;
|
|
12
|
-
const flowId = randomUUID();
|
|
13
|
-
const id = await queueAdapter.enqueue(queueName, { name: flow.entry.step, data: { ...payload, flowId, flowName } });
|
|
14
|
-
try {
|
|
15
|
-
await eventsManager.publishBus({ type: "flow.start", runId: flowId, flowName, data: { input: payload } });
|
|
16
|
-
} catch {
|
|
17
|
-
}
|
|
18
|
-
return { id, queue: queueName, step: flow.entry.step, flowId };
|
|
19
|
-
};
|
|
20
|
-
const emit = async (trigger, payload = {}) => {
|
|
21
|
-
const flowId = payload?.flowId;
|
|
22
|
-
const flowName = payload?.flowName || "unknown";
|
|
23
|
-
if (!flowId) {
|
|
24
|
-
logger.warn("emit called without flowId, trigger may not work", { trigger });
|
|
25
|
-
}
|
|
26
|
-
const { flowId: _, flowName: __, ...actualPayload } = payload;
|
|
27
|
-
try {
|
|
28
|
-
await eventsManager.publishBus({
|
|
29
|
-
type: "emit",
|
|
30
|
-
runId: flowId || "unknown",
|
|
31
|
-
flowName,
|
|
32
|
-
data: {
|
|
33
|
-
name: trigger,
|
|
34
|
-
payload: actualPayload
|
|
35
|
-
// Store actual payload separately
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
} catch (err) {
|
|
39
|
-
logger.error("Failed to emit trigger event", { trigger, error: err });
|
|
40
|
-
}
|
|
41
|
-
return [];
|
|
42
|
-
};
|
|
43
|
-
return { startFlow, emit };
|
|
44
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export interface LogReadOptions {
|
|
2
|
-
fromId?: string;
|
|
3
|
-
limit?: number;
|
|
4
|
-
}
|
|
5
|
-
export declare function useLogs(): {
|
|
6
|
-
getJobLogs: (_jobId: string, _opts?: {
|
|
7
|
-
limit?: number;
|
|
8
|
-
fromId?: string;
|
|
9
|
-
direction?: "forward" | "backward";
|
|
10
|
-
paged?: boolean;
|
|
11
|
-
}) => Promise<any>;
|
|
12
|
-
getFlowRunLogs: (flowId: string, opts?: {
|
|
13
|
-
limit?: number;
|
|
14
|
-
fromId?: string;
|
|
15
|
-
direction?: "forward" | "backward";
|
|
16
|
-
paged?: boolean;
|
|
17
|
-
}) => Promise<any>;
|
|
18
|
-
publishLog: (level: "debug" | "info" | "warn" | "error", msg: string, meta?: any, ctx?: {
|
|
19
|
-
queue?: string;
|
|
20
|
-
jobId?: string;
|
|
21
|
-
flowId?: string;
|
|
22
|
-
}) => Promise<void>;
|
|
23
|
-
onLog: (handler: (e: {
|
|
24
|
-
level: "debug" | "info" | "warn" | "error";
|
|
25
|
-
msg: string;
|
|
26
|
-
meta?: any;
|
|
27
|
-
raw: any;
|
|
28
|
-
}) => void) => any;
|
|
29
|
-
onJobLog: (_jobId: string, _handler: (e: {
|
|
30
|
-
level: "debug" | "info" | "warn" | "error";
|
|
31
|
-
msg: string;
|
|
32
|
-
meta?: any;
|
|
33
|
-
raw: any;
|
|
34
|
-
}) => void) => () => void;
|
|
35
|
-
onFlowLog: (flowId: string, handler: (e: {
|
|
36
|
-
level: "debug" | "info" | "warn" | "error";
|
|
37
|
-
msg: string;
|
|
38
|
-
meta?: any;
|
|
39
|
-
raw: any;
|
|
40
|
-
}) => void) => any;
|
|
41
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { useEventManager, useEventStore } from "#imports";
|
|
2
|
-
export function useLogs() {
|
|
3
|
-
const eventManager = useEventManager();
|
|
4
|
-
const store = useEventStore();
|
|
5
|
-
const names = store.names();
|
|
6
|
-
async function getJobLogs(_jobId, _opts) {
|
|
7
|
-
return { items: [], nextFromId: void 0 };
|
|
8
|
-
}
|
|
9
|
-
async function getFlowRunLogs(flowId, opts) {
|
|
10
|
-
const s = names.flow(flowId);
|
|
11
|
-
const limit = opts?.limit ?? 200;
|
|
12
|
-
const direction = opts?.direction || "backward";
|
|
13
|
-
if (opts?.paged) {
|
|
14
|
-
const page2 = await store.read(s, { limit: limit * 5, fromId: opts?.fromId, direction });
|
|
15
|
-
const filtered = page2.filter((r) => r?.kind === "runner.log");
|
|
16
|
-
const items = filtered.slice(0, limit);
|
|
17
|
-
const nextFromId = page2.length >= limit * 5 ? page2[page2.length - 1]?.id : void 0;
|
|
18
|
-
return { items, nextFromId };
|
|
19
|
-
}
|
|
20
|
-
const page = await store.read(s, { limit, fromId: opts?.fromId, direction });
|
|
21
|
-
return page.filter((r) => r?.kind === "runner.log").slice(0, limit);
|
|
22
|
-
}
|
|
23
|
-
async function publishLog(level, msg, meta, ctx) {
|
|
24
|
-
const reserved = /* @__PURE__ */ new Set(["flowId", "flowName", "stepName", "stepRunId", "stepId", "attempt", "jobId", "queue", "tags"]);
|
|
25
|
-
const envMeta = {};
|
|
26
|
-
const dataMeta = {};
|
|
27
|
-
const src = meta || {};
|
|
28
|
-
for (const k of Object.keys(src)) {
|
|
29
|
-
if (reserved.has(k)) envMeta[k] = src[k];
|
|
30
|
-
else dataMeta[k] = src[k];
|
|
31
|
-
}
|
|
32
|
-
if (ctx?.flowId && envMeta.flowId == null) envMeta.flowId = ctx.flowId;
|
|
33
|
-
const runId = ctx?.flowId || "unknown";
|
|
34
|
-
const flowName = envMeta.flowName || "unknown";
|
|
35
|
-
const stepName = envMeta.stepName;
|
|
36
|
-
const stepId = envMeta.stepId || envMeta.stepRunId;
|
|
37
|
-
const attempt = envMeta.attempt;
|
|
38
|
-
await eventManager.publishBus({
|
|
39
|
-
type: "log",
|
|
40
|
-
runId,
|
|
41
|
-
flowName,
|
|
42
|
-
stepName,
|
|
43
|
-
stepId,
|
|
44
|
-
attempt,
|
|
45
|
-
data: { level, message: msg, ...dataMeta }
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function onLog(handler) {
|
|
49
|
-
return eventManager.onType("log", (evt) => {
|
|
50
|
-
const d = evt?.data || {};
|
|
51
|
-
handler({ level: d.level, msg: d.message || d.msg, meta: d.meta, raw: evt });
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function onJobLog(_jobId, _handler) {
|
|
55
|
-
return () => {
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function onFlowLog(flowId, handler) {
|
|
59
|
-
const s = names.flow(flowId);
|
|
60
|
-
return store.subscribe(s, (evt) => {
|
|
61
|
-
if (evt?.kind !== "runner.log") return;
|
|
62
|
-
const d = evt?.data || {};
|
|
63
|
-
handler({ level: d.level, msg: d.msg, meta: d.meta, raw: evt });
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
getJobLogs,
|
|
68
|
-
getFlowRunLogs,
|
|
69
|
-
publishLog,
|
|
70
|
-
onLog,
|
|
71
|
-
onJobLog,
|
|
72
|
-
onFlowLog
|
|
73
|
-
};
|
|
74
|
-
}
|