nvent 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.d.mts +4 -185
- package/dist/module.json +3 -3
- package/dist/module.mjs +451 -257
- package/dist/runtime/adapters/base/index.d.ts +6 -0
- package/dist/runtime/adapters/base/index.js +1 -0
- package/dist/runtime/adapters/base/store-validator.d.ts +48 -0
- package/dist/runtime/adapters/base/store-validator.js +147 -0
- package/dist/runtime/adapters/builtin/file-queue.d.ts +67 -0
- package/dist/runtime/adapters/builtin/file-queue.js +499 -0
- package/dist/runtime/adapters/builtin/file-store.d.ts +32 -0
- package/dist/runtime/adapters/builtin/file-store.js +206 -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 +243 -0
- package/dist/runtime/adapters/builtin/memory-store.d.ts +68 -0
- package/dist/runtime/adapters/builtin/memory-store.js +333 -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 +134 -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 +297 -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 +175 -0
- package/dist/runtime/config/types.d.ts +397 -0
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/{server-utils/events → events}/eventBus.d.ts +1 -1
- package/dist/runtime/events/types.d.ts +145 -0
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +8 -0
- package/dist/runtime/events/utils/scheduleTrigger.js +69 -0
- package/dist/runtime/events/utils/stallDetector.d.ts +140 -0
- package/dist/runtime/events/utils/stallDetector.js +436 -0
- package/dist/runtime/events/utils/triggerRuntime.d.ts +58 -0
- package/dist/runtime/events/utils/triggerRuntime.js +212 -0
- package/dist/runtime/{server-utils/events → events}/wiring/flowWiring.d.ts +12 -11
- package/dist/runtime/events/wiring/flowWiring.js +1020 -0
- package/dist/runtime/events/wiring/registry.d.ts +19 -0
- package/dist/runtime/events/wiring/registry.js +35 -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 +36 -0
- package/dist/runtime/events/wiring/streamWiring.js +156 -0
- package/dist/runtime/events/wiring/triggerWiring.d.ts +21 -0
- package/dist/runtime/events/wiring/triggerWiring.js +412 -0
- package/dist/runtime/nitro/plugins/00.adapters.d.ts +14 -0
- package/dist/runtime/nitro/plugins/00.adapters.js +73 -0
- package/dist/runtime/nitro/plugins/02.workers.js +63 -0
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +12 -0
- package/dist/runtime/nitro/plugins/03.triggers.js +55 -0
- package/dist/runtime/nitro/routes/webhook.await.d.ts +23 -0
- package/dist/runtime/nitro/routes/webhook.await.js +90 -0
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +69 -0
- package/dist/runtime/nitro/routes/webhook.trigger.js +64 -0
- package/dist/runtime/nitro/utils/adapters.d.ts +66 -0
- package/dist/runtime/nitro/utils/adapters.js +51 -0
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +120 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +28 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +55 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +16 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +78 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +67 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +120 -0
- package/dist/runtime/nitro/utils/defineFunction.d.ts +10 -0
- package/dist/runtime/nitro/utils/defineFunction.js +17 -0
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +310 -0
- package/dist/runtime/nitro/utils/defineFunctionConfig.js +3 -0
- package/dist/runtime/nitro/utils/defineHooks.d.ts +41 -0
- package/dist/runtime/nitro/utils/defineHooks.js +6 -0
- package/dist/runtime/nitro/utils/registerAdapter.d.ts +59 -0
- package/dist/runtime/nitro/utils/registerAdapter.js +13 -0
- package/dist/runtime/nitro/utils/useAwait.d.ts +71 -0
- package/dist/runtime/nitro/utils/useAwait.js +139 -0
- package/dist/runtime/{server-utils → nitro}/utils/useEventManager.d.ts +2 -2
- package/dist/runtime/{server-utils → nitro}/utils/useEventManager.js +1 -1
- package/dist/runtime/nitro/utils/useFlow.d.ts +68 -0
- package/dist/runtime/nitro/utils/useFlow.js +226 -0
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +34 -0
- package/dist/runtime/nitro/utils/useHookRegistry.js +25 -0
- package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.js +2 -2
- package/dist/runtime/nitro/utils/useRunContext.d.ts +6 -0
- package/dist/runtime/nitro/utils/useRunContext.js +102 -0
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +83 -0
- package/dist/runtime/nitro/utils/useStreamTopics.js +94 -0
- package/dist/runtime/nitro/utils/useTrigger.d.ts +150 -0
- package/dist/runtime/nitro/utils/useTrigger.js +320 -0
- package/dist/runtime/scheduler/index.d.ts +33 -0
- package/dist/runtime/scheduler/index.js +38 -0
- package/dist/runtime/scheduler/scheduler.d.ts +113 -0
- package/dist/runtime/scheduler/scheduler.js +623 -0
- package/dist/runtime/scheduler/types.d.ts +116 -0
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/tsconfig.json +8 -0
- package/dist/runtime/worker/node/runner.d.ts +53 -0
- package/dist/runtime/worker/node/runner.js +327 -0
- package/dist/types.d.mts +2 -2
- package/package.json +16 -46
- 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/api/_flows/[name]/clear-history.delete.d.ts +0 -10
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +0 -44
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +0 -7
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +0 -53
- package/dist/runtime/server/api/_flows/[name]/schedule.post.js +0 -57
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +0 -42
- package/dist/runtime/server/api/_flows/[name]/schedules.get.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules.get.js +0 -48
- package/dist/runtime/server/api/_flows/[name]/start.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/start.post.js +0 -9
- package/dist/runtime/server/api/_flows/index.get.d.ts +0 -6
- package/dist/runtime/server/api/_flows/index.get.js +0 -5
- package/dist/runtime/server/api/_flows/ws.d.ts +0 -60
- package/dist/runtime/server/api/_flows/ws.js +0 -188
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +0 -9
- package/dist/runtime/server/api/_queues/[name]/job/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/index.get.js +0 -18
- package/dist/runtime/server/api/_queues/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/index.get.js +0 -63
- package/dist/runtime/server/api/_queues/ws.d.ts +0 -48
- package/dist/runtime/server/api/_queues/ws.js +0 -205
- 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.d.ts +0 -2
- 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.d.ts +0 -2
- 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/flowWiring.js +0 -409
- 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.d.ts +0 -154
- 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/defineQueueWorker.js +0 -17
- 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/server-utils/worker/runner/node.d.ts +0 -27
- package/dist/runtime/server-utils/worker/runner/node.js +0 -196
- 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.js +0 -0
- /package/dist/runtime/{server/plugins/00.ws-lifecycle.d.ts → nitro/plugins/01.ws-lifecycle.d.ts} +0 -0
- /package/dist/runtime/{server/plugins/00.ws-lifecycle.js → nitro/plugins/01.ws-lifecycle.js} +0 -0
- /package/dist/runtime/{server/api/_flows/[name]/schedule.post.d.ts → nitro/plugins/02.workers.d.ts} +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/useNventLogger.d.ts +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.d.ts +0 -0
- /package/dist/runtime/{server-utils → nitro}/utils/wsPeerManager.js +0 -0
- /package/dist/runtime/{python → worker/python}/get_config.py +0 -0
|
@@ -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
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { QueueEvent, JobsQuery, ScheduleOptions, JobInput, JobCounts } from '../queue/types.js';
|
|
2
|
-
export declare const useQueue: () => {
|
|
3
|
-
enqueue: (queue: string, job: JobInput) => Promise<string>;
|
|
4
|
-
schedule: (queue: string, job: JobInput, opts?: ScheduleOptions) => Promise<string>;
|
|
5
|
-
getJob: (queue: string, id: string) => Promise<import("../queue/types.js").Job | null>;
|
|
6
|
-
getJobs: (queue: string, q?: JobsQuery) => Promise<import("../queue/types.js").Job[]>;
|
|
7
|
-
on: (queue: string, event: QueueEvent, cb: (p: any) => void) => () => void;
|
|
8
|
-
pause: (queue: string) => Promise<void>;
|
|
9
|
-
resume: (queue: string) => Promise<void>;
|
|
10
|
-
getJobCounts: (queue: string) => Promise<Record<string, number>> | {
|
|
11
|
-
new (executor: (resolve: (value: JobCounts | PromiseLike<JobCounts>) => void, reject: (reason?: any) => void) => void): Promise<JobCounts>;
|
|
12
|
-
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
|
|
13
|
-
all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>;
|
|
14
|
-
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
|
|
15
|
-
race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
|
|
16
|
-
readonly prototype: Promise<any>;
|
|
17
|
-
reject<T = never>(reason?: any): Promise<T>;
|
|
18
|
-
resolve(): Promise<void>;
|
|
19
|
-
resolve<T>(value: T): Promise<Awaited<T>>;
|
|
20
|
-
resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
|
|
21
|
-
allSettled<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: PromiseSettledResult<Awaited<T[P]>>; }>;
|
|
22
|
-
allSettled<T>(values: Iterable<T | PromiseLike<T>>): Promise<PromiseSettledResult<Awaited<T>>[]>;
|
|
23
|
-
any<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
|
|
24
|
-
any<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
|
|
25
|
-
withResolvers<T>(): PromiseWithResolvers<T>;
|
|
26
|
-
try<T, U extends unknown[]>(callbackFn: (...args: U) => T | PromiseLike<T>, ...args: U): Promise<Awaited<T>>;
|
|
27
|
-
readonly [Symbol.species]: PromiseConstructor;
|
|
28
|
-
};
|
|
29
|
-
isPaused: (queue: string) => Promise<any>;
|
|
30
|
-
close: () => Promise<void>;
|
|
31
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getQueueProvider } from "../queue/queueFactory.js";
|
|
2
|
-
export const useQueue = () => {
|
|
3
|
-
const provider = getQueueProvider();
|
|
4
|
-
return {
|
|
5
|
-
// Enqueue immediately
|
|
6
|
-
enqueue: (queue, job) => provider.enqueue(queue, job),
|
|
7
|
-
// Schedule with optional delay or cron
|
|
8
|
-
schedule: (queue, job, opts) => provider.schedule(queue, job, opts),
|
|
9
|
-
// Fetch single job
|
|
10
|
-
getJob: (queue, id) => provider.getJob(queue, id),
|
|
11
|
-
// List jobs (provider decides states/pagination)
|
|
12
|
-
getJobs: (queue, q) => provider.getJobs(queue, q),
|
|
13
|
-
// Subscribe to provider-agnostic events
|
|
14
|
-
on: (queue, event, cb) => provider.on(queue, event, cb),
|
|
15
|
-
// Operational controls
|
|
16
|
-
pause: (queue) => provider.pause(queue),
|
|
17
|
-
resume: (queue) => provider.resume(queue),
|
|
18
|
-
// Optional helpers if provider exposes them
|
|
19
|
-
getJobCounts: (queue) => provider.getJobCounts ? provider.getJobCounts(queue) : Promise,
|
|
20
|
-
isPaused: (queue) => provider.isPaused ? provider.isPaused(queue) : Promise.resolve(void 0),
|
|
21
|
-
// Provider lifecycle (normally handled by plugin/provider)
|
|
22
|
-
close: () => provider.close()
|
|
23
|
-
};
|
|
24
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Worker } from 'bullmq';
|
|
2
|
-
import { type NodeHandler } from './runner/node.js';
|
|
3
|
-
export declare function closeAllWorkers(): Promise<void>;
|
|
4
|
-
export declare function registerTsWorker(queueName: string, jobName: string, handler: NodeHandler, opts?: any): Promise<Worker<any, any, string>>;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Worker } from "bullmq";
|
|
2
|
-
import { createBullMQProcessor } from "./runner/node.js";
|
|
3
|
-
import { useRuntimeConfig, useNventLogger } from "#imports";
|
|
4
|
-
const registeredWorkers = /* @__PURE__ */ new Map();
|
|
5
|
-
export async function closeAllWorkers() {
|
|
6
|
-
const logger = useNventLogger("worker-adapter");
|
|
7
|
-
const closePromises = [];
|
|
8
|
-
for (const [queueName, info] of registeredWorkers.entries()) {
|
|
9
|
-
closePromises.push(
|
|
10
|
-
info.worker.close().catch((err) => {
|
|
11
|
-
if (err.code !== "EPIPE" && !err.message?.includes("Connection is closed")) {
|
|
12
|
-
logger.warn("Error closing worker for queue", { queueName, error: err });
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
await Promise.allSettled(closePromises);
|
|
18
|
-
registeredWorkers.clear();
|
|
19
|
-
logger.info("[closeAllWorkers] All workers closed");
|
|
20
|
-
}
|
|
21
|
-
export async function registerTsWorker(queueName, jobName, handler, opts) {
|
|
22
|
-
let info = registeredWorkers.get(queueName);
|
|
23
|
-
const logger = useNventLogger("worker-adapter");
|
|
24
|
-
if (info) {
|
|
25
|
-
logger.info(`[registerTsWorker] Adding handler for job "${jobName}" to existing worker for queue "${queueName}"`);
|
|
26
|
-
info.handlers.set(jobName, handler);
|
|
27
|
-
return info.worker;
|
|
28
|
-
}
|
|
29
|
-
logger.info(`[registerTsWorker] Creating new worker for queue: ${queueName}`);
|
|
30
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
31
|
-
handlers.set(jobName, handler);
|
|
32
|
-
const dispatcher = async (job) => {
|
|
33
|
-
const handler2 = handlers.get(job.name);
|
|
34
|
-
if (!handler2) {
|
|
35
|
-
const error = `[Worker] No handler registered for job "${job.name}" on queue "${queueName}". Available handlers: ${Array.from(handlers.keys()).join(", ")}`;
|
|
36
|
-
logger.error(error);
|
|
37
|
-
throw new Error(error);
|
|
38
|
-
}
|
|
39
|
-
const processor = createBullMQProcessor(handler2, queueName);
|
|
40
|
-
return processor(job);
|
|
41
|
-
};
|
|
42
|
-
const rc = useRuntimeConfig();
|
|
43
|
-
const connection = rc?.queue?.queue?.redis;
|
|
44
|
-
const shouldPause = opts?.autorun === false;
|
|
45
|
-
const worker = new Worker(queueName, dispatcher, { connection, ...opts || {} });
|
|
46
|
-
if (shouldPause) {
|
|
47
|
-
await worker.pause();
|
|
48
|
-
logger.info(`[registerTsWorker] Worker for queue "${queueName}" created but paused (autorun: false)`);
|
|
49
|
-
} else {
|
|
50
|
-
logger.info(`[registerTsWorker] Worker for queue "${queueName}" created and running`);
|
|
51
|
-
}
|
|
52
|
-
worker.on("error", (err) => {
|
|
53
|
-
logger.error(`[Worker] Error in worker for queue "${queueName}":`, err);
|
|
54
|
-
});
|
|
55
|
-
worker.on("failed", (job, err) => {
|
|
56
|
-
logger.error(`[Worker] Job failed in worker for queue "${queueName}":`, {
|
|
57
|
-
jobId: job?.id,
|
|
58
|
-
jobName: job?.name,
|
|
59
|
-
error: err.message,
|
|
60
|
-
stack: err.stack
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
info = { worker, handlers };
|
|
64
|
-
registeredWorkers.set(queueName, info);
|
|
65
|
-
return worker;
|
|
66
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Job as BullJob } from 'bullmq';
|
|
2
|
-
import { useFlowEngine } from '#imports';
|
|
3
|
-
export interface RunLogger {
|
|
4
|
-
log: (level: 'debug' | 'info' | 'warn' | 'error', msg: string, meta?: any) => void;
|
|
5
|
-
}
|
|
6
|
-
export interface RunState {
|
|
7
|
-
get<T = any>(key: string): Promise<T | null>;
|
|
8
|
-
set<T = any>(key: string, value: T, opts?: {
|
|
9
|
-
ttl?: number;
|
|
10
|
-
}): Promise<void>;
|
|
11
|
-
delete(key: string): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export interface RunContext {
|
|
14
|
-
jobId?: string;
|
|
15
|
-
queue?: string;
|
|
16
|
-
flowId?: string;
|
|
17
|
-
flowName?: string;
|
|
18
|
-
stepName?: string;
|
|
19
|
-
stepId?: string;
|
|
20
|
-
attempt?: number;
|
|
21
|
-
logger: RunLogger;
|
|
22
|
-
state: RunState;
|
|
23
|
-
flow: ReturnType<typeof useFlowEngine>;
|
|
24
|
-
}
|
|
25
|
-
export declare function buildContext(partial?: Partial<RunContext>): RunContext;
|
|
26
|
-
export type NodeHandler = (input: any, ctx: RunContext) => Promise<any>;
|
|
27
|
-
export declare function createBullMQProcessor(handler: NodeHandler, queueName: string): (job: BullJob) => Promise<any>;
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { getStateProvider } from "../../state/stateFactory.js";
|
|
3
|
-
import { useRuntimeConfig, useLogs, useFlowEngine, useEventManager, useNventLogger } from "#imports";
|
|
4
|
-
const defaultState = {
|
|
5
|
-
async get() {
|
|
6
|
-
return null;
|
|
7
|
-
},
|
|
8
|
-
async set() {
|
|
9
|
-
},
|
|
10
|
-
async delete() {
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
function scopeKey(baseKey, flowId) {
|
|
14
|
-
if (!flowId) return baseKey;
|
|
15
|
-
return `flow:${flowId}:${baseKey}`;
|
|
16
|
-
}
|
|
17
|
-
export function buildContext(partial) {
|
|
18
|
-
const state = partial?.state || (() => {
|
|
19
|
-
try {
|
|
20
|
-
const state2 = getStateProvider();
|
|
21
|
-
const rc = useRuntimeConfig();
|
|
22
|
-
const cleanupCfg = rc?.queue?.state?.cleanup || { strategy: "never" };
|
|
23
|
-
return {
|
|
24
|
-
async get(key) {
|
|
25
|
-
return state2.get(scopeKey(key, partial?.flowId));
|
|
26
|
-
},
|
|
27
|
-
async set(key, value, opts) {
|
|
28
|
-
const ttl = opts?.ttl ?? (cleanupCfg?.strategy === "ttl" ? cleanupCfg?.ttlMs : void 0);
|
|
29
|
-
return state2.set(scopeKey(key, partial?.flowId), value, ttl ? { ttl } : void 0);
|
|
30
|
-
},
|
|
31
|
-
async delete(key) {
|
|
32
|
-
return state2.delete(scopeKey(key, partial?.flowId));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
} catch {
|
|
36
|
-
return defaultState;
|
|
37
|
-
}
|
|
38
|
-
})();
|
|
39
|
-
const logger = partial?.logger || (() => {
|
|
40
|
-
const logs = useLogs();
|
|
41
|
-
return {
|
|
42
|
-
log: (level, msg, meta) => {
|
|
43
|
-
const mergedMeta = { ...meta || {} };
|
|
44
|
-
void logs.publishLog(level, msg, mergedMeta, { queue: partial?.queue, jobId: partial?.jobId, flowId: partial?.flowId });
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
})();
|
|
48
|
-
const baseFlowEngine = useFlowEngine();
|
|
49
|
-
const flow = {
|
|
50
|
-
...baseFlowEngine,
|
|
51
|
-
emit: async (trigger, payload = {}) => {
|
|
52
|
-
const enrichedPayload = {
|
|
53
|
-
...payload,
|
|
54
|
-
flowId: payload.flowId || partial?.flowId,
|
|
55
|
-
flowName: payload.flowName || partial?.flowName
|
|
56
|
-
};
|
|
57
|
-
return baseFlowEngine.emit(trigger, enrichedPayload);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
jobId: partial?.jobId,
|
|
62
|
-
queue: partial?.queue,
|
|
63
|
-
flowId: partial?.flowId,
|
|
64
|
-
flowName: partial?.flowName,
|
|
65
|
-
stepName: partial?.stepName,
|
|
66
|
-
stepId: partial?.stepId,
|
|
67
|
-
attempt: partial?.attempt,
|
|
68
|
-
logger,
|
|
69
|
-
state,
|
|
70
|
-
flow
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export function createBullMQProcessor(handler, queueName) {
|
|
74
|
-
const logger = useNventLogger("node-runner");
|
|
75
|
-
return async function processor(job) {
|
|
76
|
-
if (job.data?.__scheduledFlowStart) {
|
|
77
|
-
const { __flowName, __flowInput } = job.data;
|
|
78
|
-
try {
|
|
79
|
-
const { startFlow } = useFlowEngine();
|
|
80
|
-
const result2 = await startFlow(__flowName, __flowInput || {});
|
|
81
|
-
return {
|
|
82
|
-
scheduled: true,
|
|
83
|
-
flowId: result2.flowId,
|
|
84
|
-
flowName: __flowName
|
|
85
|
-
};
|
|
86
|
-
} catch (err) {
|
|
87
|
-
logger.error("[scheduled-flow] Failed to start flow:", err);
|
|
88
|
-
throw err;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const eventMgr = useEventManager();
|
|
92
|
-
const rc = useRuntimeConfig();
|
|
93
|
-
const autoScope = rc?.queue?.state?.autoScope || "always";
|
|
94
|
-
const providedFlow = job.data?.flowId;
|
|
95
|
-
const flowId = providedFlow || (autoScope === "always" ? randomUUID() : void 0);
|
|
96
|
-
const attempt = (job.attemptsMade || 0) + 1;
|
|
97
|
-
const maxAttempts = job.opts?.attempts || 1;
|
|
98
|
-
const isFinalAttempt = attempt >= maxAttempts;
|
|
99
|
-
const stepRunId = `${String(flowId || job.id)}__${job.name}__attempt-${attempt}`;
|
|
100
|
-
const flowName = job.data?.flowName || "unknown";
|
|
101
|
-
const ctx = buildContext({
|
|
102
|
-
jobId: job.id,
|
|
103
|
-
queue: queueName,
|
|
104
|
-
flowId,
|
|
105
|
-
flowName,
|
|
106
|
-
stepName: job.name,
|
|
107
|
-
stepId: stepRunId,
|
|
108
|
-
attempt
|
|
109
|
-
});
|
|
110
|
-
const attemptLogger = {
|
|
111
|
-
log: (level, msg, meta) => {
|
|
112
|
-
const enriched = { ...meta || {}, stepName: job.name, attempt, stepRunId, flowName };
|
|
113
|
-
ctx.logger.log(level, msg, enriched);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
try {
|
|
117
|
-
await eventMgr.publishBus({
|
|
118
|
-
type: "step.started",
|
|
119
|
-
runId: flowId || "unknown",
|
|
120
|
-
flowName,
|
|
121
|
-
stepName: job.name,
|
|
122
|
-
stepId: stepRunId,
|
|
123
|
-
attempt,
|
|
124
|
-
data: { jobId: job.id, name: job.name, queue: queueName }
|
|
125
|
-
});
|
|
126
|
-
} catch {
|
|
127
|
-
}
|
|
128
|
-
let result;
|
|
129
|
-
try {
|
|
130
|
-
const workerInput = job.data?.input !== void 0 ? job.data.input : job.data;
|
|
131
|
-
result = await handler(workerInput, { ...ctx, logger: attemptLogger });
|
|
132
|
-
} catch (err) {
|
|
133
|
-
logger.error(`[worker] Job failed: ${job.name} (${job.id})`, {
|
|
134
|
-
queue: queueName,
|
|
135
|
-
flowId,
|
|
136
|
-
flowName,
|
|
137
|
-
stepName: job.name,
|
|
138
|
-
error: err?.message || String(err),
|
|
139
|
-
stack: err?.stack
|
|
140
|
-
});
|
|
141
|
-
const willRetry = !isFinalAttempt;
|
|
142
|
-
try {
|
|
143
|
-
await eventMgr.publishBus({
|
|
144
|
-
type: "step.failed",
|
|
145
|
-
runId: flowId || "unknown",
|
|
146
|
-
flowName,
|
|
147
|
-
stepName: job.name,
|
|
148
|
-
stepId: stepRunId,
|
|
149
|
-
attempt,
|
|
150
|
-
data: {
|
|
151
|
-
error: String(err?.message || err),
|
|
152
|
-
stack: err?.stack
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
} catch {
|
|
156
|
-
}
|
|
157
|
-
if (willRetry) {
|
|
158
|
-
try {
|
|
159
|
-
await eventMgr.publishBus({
|
|
160
|
-
type: "step.retry",
|
|
161
|
-
runId: flowId || "unknown",
|
|
162
|
-
flowName,
|
|
163
|
-
stepName: job.name,
|
|
164
|
-
stepId: stepRunId,
|
|
165
|
-
attempt,
|
|
166
|
-
data: {
|
|
167
|
-
stepName: job.name,
|
|
168
|
-
queue: queueName,
|
|
169
|
-
error: String(err?.message || err),
|
|
170
|
-
stack: err?.stack,
|
|
171
|
-
attempt,
|
|
172
|
-
maxAttempts,
|
|
173
|
-
nextAttempt: attempt + 1
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
} catch {
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
throw err;
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
const eventMgr2 = useEventManager();
|
|
183
|
-
await eventMgr2.publishBus({
|
|
184
|
-
type: "step.completed",
|
|
185
|
-
runId: flowId || "unknown",
|
|
186
|
-
flowName,
|
|
187
|
-
stepName: job.name,
|
|
188
|
-
stepId: stepRunId,
|
|
189
|
-
attempt,
|
|
190
|
-
data: { result }
|
|
191
|
-
});
|
|
192
|
-
} catch {
|
|
193
|
-
}
|
|
194
|
-
return result;
|
|
195
|
-
};
|
|
196
|
-
}
|
package/dist/runtime/types.d.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type { WorkerOptions as BullmqWorkerOptions } from 'bullmq'
|
|
2
|
-
import type z from 'zod'
|
|
3
|
-
import type colors from 'tailwindcss/colors'
|
|
4
|
-
import type { JobSchemaArray, JobSchema } from './schema'
|
|
5
|
-
|
|
6
|
-
type NeutralColor = 'slate' | 'gray' | 'zinc' | 'neutral' | 'stone'
|
|
7
|
-
export type Color = Exclude<keyof typeof colors, 'inherit' | 'current' | 'transparent' | 'black' | 'white' | NeutralColor> | NeutralColor
|
|
8
|
-
|
|
9
|
-
export type Jobs = z.infer<typeof JobSchemaArray>
|
|
10
|
-
export type Job = z.infer<typeof JobSchema>
|
|
11
|
-
|
|
12
|
-
export type WorkerOptions = Omit<BullmqWorkerOptions, 'connection' | 'useWorkerThreads'>
|
|
13
|
-
|
|
14
|
-
export type WorkerConfig = Record<string, WorkerOptions>
|
|
15
|
-
|
|
16
|
-
export type QueueData = {
|
|
17
|
-
name: string
|
|
18
|
-
origin: 'remote' | 'local'
|
|
19
|
-
active: boolean
|
|
20
|
-
jobs: JobCounts
|
|
21
|
-
worker: number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Declarations for worker authoring helpers available via auto-imports at runtime
|
|
25
|
-
// These declarations make TS happy in worker files and tests.
|
|
26
|
-
export declare function defineQueueWorker(processor: (...args: any[]) => any): any
|
|
27
|
-
export declare function defineQueueConfig(cfg: any): any
|
|
28
|
-
|
|
29
|
-
// v0.4 Event Schema
|
|
30
|
-
export type EventType = 'flow.start' | 'flow.completed' | 'flow.failed' | 'step.started' | 'step.completed' | 'step.failed' | 'step.retry' | 'log' | 'emit' | 'state'
|
|
31
|
-
|
|
32
|
-
export interface BaseEvent {
|
|
33
|
-
id?: string // Redis stream ID (auto-generated, not present for ingress events)
|
|
34
|
-
ts?: string // ISO timestamp (auto-generated, not present for ingress events)
|
|
35
|
-
type: EventType
|
|
36
|
-
runId: string // Flow run UUID
|
|
37
|
-
flowName: string // Flow definition name
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface StepEvent extends BaseEvent {
|
|
41
|
-
stepName: string
|
|
42
|
-
stepId: string
|
|
43
|
-
attempt: number
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface FlowStartEvent extends BaseEvent {
|
|
47
|
-
type: 'flow.start'
|
|
48
|
-
data?: {
|
|
49
|
-
input?: any
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface FlowCompletedEvent extends BaseEvent {
|
|
54
|
-
type: 'flow.completed'
|
|
55
|
-
data?: {
|
|
56
|
-
result?: any
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface FlowFailedEvent extends BaseEvent {
|
|
61
|
-
type: 'flow.failed'
|
|
62
|
-
data?: {
|
|
63
|
-
error?: string
|
|
64
|
-
stack?: string
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface StepStartedEvent extends StepEvent {
|
|
69
|
-
type: 'step.started'
|
|
70
|
-
data?: {
|
|
71
|
-
input?: any
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface StepCompletedEvent extends StepEvent {
|
|
76
|
-
type: 'step.completed'
|
|
77
|
-
data?: {
|
|
78
|
-
result?: any
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface StepFailedEvent extends StepEvent {
|
|
83
|
-
type: 'step.failed'
|
|
84
|
-
data?: {
|
|
85
|
-
error?: string
|
|
86
|
-
stack?: string
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface StepRetryEvent extends StepEvent {
|
|
91
|
-
type: 'step.retry'
|
|
92
|
-
data?: {
|
|
93
|
-
stepName: string
|
|
94
|
-
queue: string
|
|
95
|
-
error?: string
|
|
96
|
-
stack?: string
|
|
97
|
-
attempt: number
|
|
98
|
-
maxAttempts: number
|
|
99
|
-
nextAttempt: number
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface LogEvent extends StepEvent {
|
|
104
|
-
type: 'log'
|
|
105
|
-
data: {
|
|
106
|
-
level: 'debug' | 'info' | 'warn' | 'error'
|
|
107
|
-
message: string
|
|
108
|
-
[key: string]: any
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface EmitEvent extends StepEvent {
|
|
113
|
-
type: 'emit'
|
|
114
|
-
data: {
|
|
115
|
-
topic: string
|
|
116
|
-
payload: any
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface StateEvent extends StepEvent {
|
|
121
|
-
type: 'state'
|
|
122
|
-
data: {
|
|
123
|
-
operation: 'get' | 'set' | 'delete'
|
|
124
|
-
scope?: string
|
|
125
|
-
key: string
|
|
126
|
-
value?: any
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export type FlowEvent = FlowStartEvent | FlowCompletedEvent | FlowFailedEvent | StepStartedEvent | StepCompletedEvent | StepFailedEvent | StepRetryEvent | LogEvent | EmitEvent | StateEvent
|
|
131
|
-
|
|
132
|
-
export type EventRecord = FlowEvent
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/runtime/{server/plugins/00.ws-lifecycle.d.ts → nitro/plugins/01.ws-lifecycle.d.ts}
RENAMED
|
File without changes
|
/package/dist/runtime/{server/plugins/00.ws-lifecycle.js → nitro/plugins/01.ws-lifecycle.js}
RENAMED
|
File without changes
|
/package/dist/runtime/{server/api/_flows/[name]/schedule.post.d.ts → nitro/plugins/02.workers.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|