nvent 0.5.15 → 1.0.0-alpha.2
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 +181 -8
- package/dist/module.json +1 -1
- package/dist/module.mjs +1257 -1196
- package/dist/runtime/app/composables/useFunctionCall.d.ts +17 -0
- package/dist/runtime/app/composables/useFunctionCall.js +25 -0
- package/dist/runtime/app/composables/useNventStream.d.ts +23 -0
- package/dist/runtime/app/composables/useNventStream.js +58 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.d.ts +19 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.js +62 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.d.ts +15 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.js +91 -0
- package/dist/runtime/nitro/routes/stream-proxy.d.ts +17 -0
- package/dist/runtime/nitro/routes/stream-proxy.js +45 -0
- package/dist/runtime/nitro/utils/console.d.ts +32 -0
- package/dist/runtime/nitro/utils/console.js +95 -0
- package/dist/runtime/nitro/utils/defineFunction.d.ts +378 -3
- package/dist/runtime/nitro/utils/defineFunction.js +224 -4
- package/dist/runtime/nitro/utils/engine.d.ts +25 -0
- package/dist/runtime/nitro/utils/engine.js +130 -0
- package/dist/runtime/nitro/utils/nventDir.d.ts +1 -0
- package/dist/runtime/nitro/utils/nventDir.js +20 -0
- package/dist/runtime/nitro/utils/useIii.d.ts +23 -0
- package/dist/runtime/nitro/utils/useIii.js +14 -0
- package/dist/runtime/nitro/utils/workers/node.d.ts +24 -0
- package/dist/runtime/nitro/utils/workers/node.js +57 -0
- package/dist/runtime/nitro/utils/workers/python.d.ts +67 -0
- package/dist/runtime/nitro/utils/workers/python.js +220 -0
- package/dist/runtime/python/nvent.py +208 -0
- package/dist/runtime/python/worker_runtime.py +659 -0
- package/dist/runtime/virtual.d.ts +17 -0
- package/dist/types.d.mts +5 -1
- package/package.json +11 -14
- package/dist/runtime/adapters/base/index.d.ts +0 -6
- package/dist/runtime/adapters/base/index.js +0 -1
- package/dist/runtime/adapters/base/store-validator.d.ts +0 -48
- package/dist/runtime/adapters/base/store-validator.js +0 -147
- package/dist/runtime/adapters/builtin/file-queue.d.ts +0 -67
- package/dist/runtime/adapters/builtin/file-queue.js +0 -499
- package/dist/runtime/adapters/builtin/file-store.d.ts +0 -32
- package/dist/runtime/adapters/builtin/file-store.js +0 -206
- package/dist/runtime/adapters/builtin/file-stream.d.ts +0 -39
- package/dist/runtime/adapters/builtin/file-stream.js +0 -56
- package/dist/runtime/adapters/builtin/index.d.ts +0 -10
- package/dist/runtime/adapters/builtin/index.js +0 -5
- package/dist/runtime/adapters/builtin/memory-queue.d.ts +0 -52
- package/dist/runtime/adapters/builtin/memory-queue.js +0 -243
- package/dist/runtime/adapters/builtin/memory-store.d.ts +0 -69
- package/dist/runtime/adapters/builtin/memory-store.js +0 -357
- package/dist/runtime/adapters/builtin/memory-stream.d.ts +0 -21
- package/dist/runtime/adapters/builtin/memory-stream.js +0 -56
- package/dist/runtime/adapters/factory.d.ts +0 -31
- package/dist/runtime/adapters/factory.js +0 -135
- package/dist/runtime/adapters/index.d.ts +0 -8
- package/dist/runtime/adapters/index.js +0 -3
- package/dist/runtime/adapters/interfaces/index.d.ts +0 -11
- package/dist/runtime/adapters/interfaces/index.js +0 -3
- package/dist/runtime/adapters/interfaces/queue.d.ts +0 -155
- package/dist/runtime/adapters/interfaces/queue.js +0 -0
- package/dist/runtime/adapters/interfaces/store.d.ts +0 -299
- package/dist/runtime/adapters/interfaces/store.js +0 -0
- package/dist/runtime/adapters/interfaces/stream.d.ts +0 -62
- package/dist/runtime/adapters/interfaces/stream.js +0 -0
- package/dist/runtime/adapters/registry.d.ts +0 -85
- package/dist/runtime/adapters/registry.js +0 -161
- package/dist/runtime/config/index.d.ts +0 -23
- package/dist/runtime/config/index.js +0 -200
- package/dist/runtime/config/types.d.ts +0 -439
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/events/eventBus.d.ts +0 -20
- package/dist/runtime/events/eventBus.js +0 -35
- package/dist/runtime/events/types.d.ts +0 -144
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +0 -8
- package/dist/runtime/events/utils/scheduleTrigger.js +0 -71
- package/dist/runtime/events/utils/stallDetector.d.ts +0 -83
- package/dist/runtime/events/utils/stallDetector.js +0 -318
- package/dist/runtime/events/utils/triggerRuntime.d.ts +0 -58
- package/dist/runtime/events/utils/triggerRuntime.js +0 -212
- package/dist/runtime/events/wiring/flowWiring.d.ts +0 -34
- package/dist/runtime/events/wiring/flowWiring.js +0 -1258
- package/dist/runtime/events/wiring/registry.d.ts +0 -19
- package/dist/runtime/events/wiring/registry.js +0 -43
- package/dist/runtime/events/wiring/stateWiring.d.ts +0 -37
- package/dist/runtime/events/wiring/stateWiring.js +0 -92
- package/dist/runtime/events/wiring/streamWiring.d.ts +0 -36
- package/dist/runtime/events/wiring/streamWiring.js +0 -156
- package/dist/runtime/events/wiring/triggerWiring.d.ts +0 -21
- package/dist/runtime/events/wiring/triggerWiring.js +0 -422
- package/dist/runtime/nitro/plugins/00.adapters.d.ts +0 -14
- package/dist/runtime/nitro/plugins/00.adapters.js +0 -73
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.d.ts +0 -5
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.js +0 -69
- package/dist/runtime/nitro/plugins/02.workers.d.ts +0 -2
- package/dist/runtime/nitro/plugins/02.workers.js +0 -92
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +0 -12
- package/dist/runtime/nitro/plugins/03.triggers.js +0 -55
- package/dist/runtime/nitro/routes/webhook.await.d.ts +0 -23
- package/dist/runtime/nitro/routes/webhook.await.js +0 -112
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +0 -86
- package/dist/runtime/nitro/routes/webhook.trigger.js +0 -73
- package/dist/runtime/nitro/utils/adapters.d.ts +0 -66
- package/dist/runtime/nitro/utils/adapters.js +0 -51
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +0 -128
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +0 -28
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +0 -55
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +0 -16
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +0 -83
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +0 -71
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +0 -128
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +0 -378
- package/dist/runtime/nitro/utils/defineFunctionConfig.js +0 -3
- package/dist/runtime/nitro/utils/defineHooks.d.ts +0 -95
- package/dist/runtime/nitro/utils/defineHooks.js +0 -9
- package/dist/runtime/nitro/utils/registerAdapter.d.ts +0 -59
- package/dist/runtime/nitro/utils/registerAdapter.js +0 -13
- package/dist/runtime/nitro/utils/useAwait.d.ts +0 -83
- package/dist/runtime/nitro/utils/useAwait.js +0 -169
- package/dist/runtime/nitro/utils/useEventManager.d.ts +0 -15
- package/dist/runtime/nitro/utils/useEventManager.js +0 -26
- package/dist/runtime/nitro/utils/useFlow.d.ts +0 -66
- package/dist/runtime/nitro/utils/useFlow.js +0 -310
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +0 -40
- package/dist/runtime/nitro/utils/useHookRegistry.js +0 -25
- package/dist/runtime/nitro/utils/useNventLogger.d.ts +0 -42
- package/dist/runtime/nitro/utils/useNventLogger.js +0 -54
- package/dist/runtime/nitro/utils/useRunContext.d.ts +0 -6
- package/dist/runtime/nitro/utils/useRunContext.js +0 -102
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +0 -83
- package/dist/runtime/nitro/utils/useStreamTopics.js +0 -94
- package/dist/runtime/nitro/utils/useTrigger.d.ts +0 -150
- package/dist/runtime/nitro/utils/useTrigger.js +0 -311
- package/dist/runtime/nitro/utils/wsPeerManager.d.ts +0 -44
- package/dist/runtime/nitro/utils/wsPeerManager.js +0 -32
- package/dist/runtime/scheduler/index.d.ts +0 -33
- package/dist/runtime/scheduler/index.js +0 -42
- package/dist/runtime/scheduler/scheduler.d.ts +0 -132
- package/dist/runtime/scheduler/scheduler.js +0 -799
- package/dist/runtime/scheduler/types.d.ts +0 -122
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/worker/node/runner.d.ts +0 -95
- package/dist/runtime/worker/node/runner.js +0 -272
- package/dist/runtime/worker/python/get_config.py +0 -64
- package/dist/runtime/worker/system/awaitHandlers.d.ts +0 -27
- package/dist/runtime/worker/system/awaitHandlers.js +0 -230
- package/dist/runtime/worker/system/index.d.ts +0 -24
- package/dist/runtime/worker/system/index.js +0 -39
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scheduler Types
|
|
3
|
-
*
|
|
4
|
-
* Unified scheduling system for all time-based operations in nvent:
|
|
5
|
-
* - Stall detection
|
|
6
|
-
* - Await timeouts
|
|
7
|
-
* - Trigger schedules
|
|
8
|
-
* - Cleanup jobs
|
|
9
|
-
*/
|
|
10
|
-
export interface ScheduledJob {
|
|
11
|
-
/**
|
|
12
|
-
* Unique job identifier
|
|
13
|
-
*/
|
|
14
|
-
id: string;
|
|
15
|
-
/**
|
|
16
|
-
* Human-readable job name
|
|
17
|
-
*/
|
|
18
|
-
name: string;
|
|
19
|
-
/**
|
|
20
|
-
* Job type
|
|
21
|
-
*/
|
|
22
|
-
type: 'cron' | 'interval' | 'one-time';
|
|
23
|
-
/**
|
|
24
|
-
* Cron expression (for type: 'cron')
|
|
25
|
-
* @example '0 2 * * *' - Daily at 2 AM
|
|
26
|
-
* @example '* /5 * * * *' - Every 5 minutes
|
|
27
|
-
*/
|
|
28
|
-
cron?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Interval in milliseconds (for type: 'interval')
|
|
31
|
-
*/
|
|
32
|
-
interval?: number;
|
|
33
|
-
/**
|
|
34
|
-
* Execution timestamp (for type: 'one-time')
|
|
35
|
-
*/
|
|
36
|
-
executeAt?: number;
|
|
37
|
-
/**
|
|
38
|
-
* Job handler function
|
|
39
|
-
*/
|
|
40
|
-
handler: () => Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Timezone for cron jobs
|
|
43
|
-
* @default 'UTC'
|
|
44
|
-
*/
|
|
45
|
-
timezone?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Whether the job is enabled
|
|
48
|
-
* @default true
|
|
49
|
-
*/
|
|
50
|
-
enabled?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Additional metadata
|
|
53
|
-
*/
|
|
54
|
-
metadata?: Record<string, any>;
|
|
55
|
-
/**
|
|
56
|
-
* Last execution timestamp
|
|
57
|
-
*/
|
|
58
|
-
lastRun?: number;
|
|
59
|
-
/**
|
|
60
|
-
* Next scheduled execution timestamp
|
|
61
|
-
*/
|
|
62
|
-
nextRun?: number;
|
|
63
|
-
/**
|
|
64
|
-
* Total execution count
|
|
65
|
-
*/
|
|
66
|
-
runCount?: number;
|
|
67
|
-
/**
|
|
68
|
-
* Failure count
|
|
69
|
-
*/
|
|
70
|
-
failCount?: number;
|
|
71
|
-
}
|
|
72
|
-
export interface SchedulerAdapter {
|
|
73
|
-
/**
|
|
74
|
-
* Schedule a job with distributed locking support
|
|
75
|
-
*/
|
|
76
|
-
schedule(job: ScheduledJob): Promise<string>;
|
|
77
|
-
/**
|
|
78
|
-
* Unschedule a job
|
|
79
|
-
*/
|
|
80
|
-
unschedule(jobId: string): Promise<boolean>;
|
|
81
|
-
/**
|
|
82
|
-
* Start the scheduler (begins processing scheduled jobs)
|
|
83
|
-
*/
|
|
84
|
-
start(): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Stop the scheduler and release all locks
|
|
87
|
-
*/
|
|
88
|
-
stop(): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Get all scheduled jobs (in-memory, for this instance)
|
|
91
|
-
*/
|
|
92
|
-
getScheduledJobs(): Promise<ScheduledJob[]>;
|
|
93
|
-
/**
|
|
94
|
-
* Get jobs matching a pattern (e.g., by runId)
|
|
95
|
-
* Queries persisted store, works across all instances
|
|
96
|
-
* More efficient than getAllPersistedJobs() when filtering
|
|
97
|
-
*/
|
|
98
|
-
getJobsByPattern(pattern: string): Promise<ScheduledJob[]>;
|
|
99
|
-
/**
|
|
100
|
-
* Get all persisted jobs from store (across all instances)
|
|
101
|
-
* Useful for debugging and monitoring in horizontal setups
|
|
102
|
-
*/
|
|
103
|
-
getAllPersistedJobs(): Promise<ScheduledJob[]>;
|
|
104
|
-
/**
|
|
105
|
-
* Check if scheduler is healthy
|
|
106
|
-
*/
|
|
107
|
-
isHealthy(): Promise<boolean>;
|
|
108
|
-
}
|
|
109
|
-
export interface SchedulerLock {
|
|
110
|
-
jobId: string;
|
|
111
|
-
instanceId: string;
|
|
112
|
-
acquiredAt: number;
|
|
113
|
-
expiresAt: number;
|
|
114
|
-
}
|
|
115
|
-
export interface SchedulerStats {
|
|
116
|
-
jobId: string;
|
|
117
|
-
lastRun: number;
|
|
118
|
-
nextRun?: number;
|
|
119
|
-
runCount: number;
|
|
120
|
-
failCount: number;
|
|
121
|
-
lastError?: string;
|
|
122
|
-
}
|
|
File without changes
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { FlowStats, StartFlowResult, CancelFlowResult, RunningFlow } from '../../nitro/utils/useFlow.js';
|
|
2
|
-
/**
|
|
3
|
-
* Generic job interface that works with any queue adapter
|
|
4
|
-
* Adapters should provide jobs in this format
|
|
5
|
-
*/
|
|
6
|
-
export interface QueueJob {
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
data: any;
|
|
10
|
-
attemptsMade?: number;
|
|
11
|
-
opts?: {
|
|
12
|
-
attempts?: number;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export interface RunLogger {
|
|
16
|
-
log: (level: 'debug' | 'info' | 'warn' | 'error', msg: string, meta?: any) => void;
|
|
17
|
-
}
|
|
18
|
-
export interface RunState {
|
|
19
|
-
get<T = any>(key: string): Promise<T | null>;
|
|
20
|
-
set<T = any>(key: string, value: T, opts?: {
|
|
21
|
-
ttl?: number;
|
|
22
|
-
}): Promise<void>;
|
|
23
|
-
delete(key: string): Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Flow context available within step handlers
|
|
27
|
-
* Provides context-aware versions of flow operations with auto-injected flowId/flowName
|
|
28
|
-
*/
|
|
29
|
-
export interface RunContextFlow {
|
|
30
|
-
/** Start a new flow with the given payload */
|
|
31
|
-
startFlow: (flowName: string, payload?: any) => Promise<StartFlowResult>;
|
|
32
|
-
/** Emit a trigger event (auto-injects flowId, flowName, stepName from context) */
|
|
33
|
-
emit: (trigger: string, payload?: any) => Promise<any[]>;
|
|
34
|
-
/** Cancel a specific flow by name and runId */
|
|
35
|
-
cancelFlow: (flowName: string, runId: string) => Promise<CancelFlowResult>;
|
|
36
|
-
/** Cancel the current flow (uses flowId from context) */
|
|
37
|
-
cancel: () => Promise<CancelFlowResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Check if a flow is currently running
|
|
40
|
-
* @param flowName - Optional flow name (defaults to current flow)
|
|
41
|
-
* @param runId - Optional specific run ID to check
|
|
42
|
-
* @param options - Optional configuration (auto-excludes current flow if not specified)
|
|
43
|
-
*/
|
|
44
|
-
isRunning: (flowName?: string, runId?: string, options?: {
|
|
45
|
-
excludeRunIds?: string[];
|
|
46
|
-
}) => Promise<boolean>;
|
|
47
|
-
/**
|
|
48
|
-
* Get all currently running flows
|
|
49
|
-
* @param flowName - Optional flow name (defaults to current flow)
|
|
50
|
-
* @param options - Optional configuration (auto-excludes current flow if not specified)
|
|
51
|
-
*/
|
|
52
|
-
getRunningFlows: (flowName?: string, options?: {
|
|
53
|
-
excludeRunIds?: string[];
|
|
54
|
-
}) => Promise<RunningFlow[]>;
|
|
55
|
-
/** Get flow statistics by name */
|
|
56
|
-
getFlowStats: (flowName: string) => Promise<FlowStats | null>;
|
|
57
|
-
/** Get all flows with their statistics */
|
|
58
|
-
getAllFlowStats: (options?: {
|
|
59
|
-
sortBy?: 'registeredAt' | 'lastRunAt' | 'name';
|
|
60
|
-
order?: 'asc' | 'desc';
|
|
61
|
-
limit?: number;
|
|
62
|
-
offset?: number;
|
|
63
|
-
}) => Promise<FlowStats[]>;
|
|
64
|
-
/** Check if a flow has statistics in the index */
|
|
65
|
-
hasFlowStats: (flowName: string) => Promise<boolean>;
|
|
66
|
-
}
|
|
67
|
-
export interface RunContext {
|
|
68
|
-
jobId?: string;
|
|
69
|
-
queue?: string;
|
|
70
|
-
flowId?: string;
|
|
71
|
-
flowName?: string;
|
|
72
|
-
stepName?: string;
|
|
73
|
-
stepId?: string;
|
|
74
|
-
attempt?: number;
|
|
75
|
-
logger: RunLogger;
|
|
76
|
-
state: RunState;
|
|
77
|
-
flow: RunContextFlow;
|
|
78
|
-
/**
|
|
79
|
-
* Resolved data from await pattern (awaitBefore only)
|
|
80
|
-
* Available when step resumes after await resolution
|
|
81
|
-
*/
|
|
82
|
-
trigger?: any;
|
|
83
|
-
/**
|
|
84
|
-
* Current step's await configuration
|
|
85
|
-
* Useful for conditional logic based on await settings
|
|
86
|
-
*/
|
|
87
|
-
awaitConfig?: any;
|
|
88
|
-
}
|
|
89
|
-
export declare function buildContext(partial?: Partial<RunContext>): RunContext;
|
|
90
|
-
export type NodeHandler = (input: any, ctx: RunContext) => Promise<any>;
|
|
91
|
-
/**
|
|
92
|
-
* Wraps a NodeHandler with full RunContext building and event emission
|
|
93
|
-
* Works with any queue adapter by accepting a job-like object
|
|
94
|
-
*/
|
|
95
|
-
export declare function createJobProcessor(handler: NodeHandler, queueName: string): (job: QueueJob) => Promise<any>;
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
useRuntimeConfig,
|
|
4
|
-
useFlow,
|
|
5
|
-
useEventManager,
|
|
6
|
-
useNventLogger,
|
|
7
|
-
$useFunctionRegistry,
|
|
8
|
-
$useAnalyzedFlows,
|
|
9
|
-
useStateAdapter,
|
|
10
|
-
useQueueAdapter
|
|
11
|
-
} from "#imports";
|
|
12
|
-
import { SYSTEM_HANDLERS } from "../system/index.js";
|
|
13
|
-
const logger = useNventLogger("node-runner");
|
|
14
|
-
const defaultState = {
|
|
15
|
-
async get() {
|
|
16
|
-
return null;
|
|
17
|
-
},
|
|
18
|
-
async set() {
|
|
19
|
-
},
|
|
20
|
-
async delete() {
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
function scopeKey(baseKey, flowId) {
|
|
24
|
-
if (!flowId) return baseKey;
|
|
25
|
-
return `flow:${flowId}:${baseKey}`;
|
|
26
|
-
}
|
|
27
|
-
export function buildContext(partial) {
|
|
28
|
-
const state = partial?.state || (() => {
|
|
29
|
-
try {
|
|
30
|
-
const stateAdapter = useStateAdapter();
|
|
31
|
-
const rc = useRuntimeConfig();
|
|
32
|
-
const cleanupCfg = rc?.nvent?.state?.cleanup || { strategy: "never" };
|
|
33
|
-
return {
|
|
34
|
-
async get(key) {
|
|
35
|
-
return stateAdapter.get(scopeKey(key, partial?.flowId));
|
|
36
|
-
},
|
|
37
|
-
async set(key, value, opts) {
|
|
38
|
-
const ttl = opts?.ttl ?? (cleanupCfg?.strategy === "ttl" ? cleanupCfg?.ttlMs : void 0);
|
|
39
|
-
return stateAdapter.set(scopeKey(key, partial?.flowId), value, ttl ? { ttl } : void 0);
|
|
40
|
-
},
|
|
41
|
-
async delete(key) {
|
|
42
|
-
return stateAdapter.delete(scopeKey(key, partial?.flowId));
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
} catch {
|
|
46
|
-
return defaultState;
|
|
47
|
-
}
|
|
48
|
-
})();
|
|
49
|
-
const logger2 = partial?.logger || (() => {
|
|
50
|
-
const eventManager = useEventManager();
|
|
51
|
-
return {
|
|
52
|
-
log: (level, msg, meta) => {
|
|
53
|
-
const runId = partial?.flowId || "unknown";
|
|
54
|
-
const flowName = meta?.flowName || "unknown";
|
|
55
|
-
const metaObj = meta !== null && meta !== void 0 ? typeof meta === "object" && !Array.isArray(meta) ? meta : { value: meta } : {};
|
|
56
|
-
void eventManager.publishBus({
|
|
57
|
-
type: "log",
|
|
58
|
-
runId,
|
|
59
|
-
flowName,
|
|
60
|
-
stepName: metaObj?.stepName,
|
|
61
|
-
stepId: metaObj?.stepId || metaObj?.stepRunId,
|
|
62
|
-
attempt: metaObj?.attempt,
|
|
63
|
-
data: { level, message: msg, ...metaObj }
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
})();
|
|
68
|
-
const baseFlowEngine = useFlow();
|
|
69
|
-
const flow = {
|
|
70
|
-
...baseFlowEngine,
|
|
71
|
-
emit: async (trigger, payload = {}) => {
|
|
72
|
-
const enrichedPayload = {
|
|
73
|
-
...payload,
|
|
74
|
-
flowId: payload.flowId || partial?.flowId,
|
|
75
|
-
flowName: payload.flowName || partial?.flowName,
|
|
76
|
-
stepName: payload.stepName || partial?.stepName
|
|
77
|
-
};
|
|
78
|
-
return baseFlowEngine.emit(trigger, enrichedPayload);
|
|
79
|
-
},
|
|
80
|
-
cancel: async () => {
|
|
81
|
-
if (!partial?.flowName || !partial?.flowId) {
|
|
82
|
-
throw new Error("Cannot cancel flow: flowName or flowId not available in context");
|
|
83
|
-
}
|
|
84
|
-
return baseFlowEngine.cancelFlow(partial.flowName, partial.flowId);
|
|
85
|
-
},
|
|
86
|
-
isRunning: async (flowName, runId, options) => {
|
|
87
|
-
const targetFlowName = flowName || partial?.flowName;
|
|
88
|
-
if (!targetFlowName) {
|
|
89
|
-
throw new Error("flowName is required to check if flow is running");
|
|
90
|
-
}
|
|
91
|
-
const effectiveOptions = options || (partial?.flowId ? { excludeRunIds: [partial.flowId] } : void 0);
|
|
92
|
-
return baseFlowEngine.isRunning(targetFlowName, runId, effectiveOptions);
|
|
93
|
-
},
|
|
94
|
-
getRunningFlows: async (flowName, options) => {
|
|
95
|
-
const targetFlowName = flowName || partial?.flowName;
|
|
96
|
-
if (!targetFlowName) {
|
|
97
|
-
throw new Error("flowName is required to get running flows");
|
|
98
|
-
}
|
|
99
|
-
const effectiveOptions = options || (partial?.flowId ? { excludeRunIds: [partial.flowId] } : void 0);
|
|
100
|
-
return baseFlowEngine.getRunningFlows(targetFlowName, effectiveOptions);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
return {
|
|
104
|
-
jobId: partial?.jobId,
|
|
105
|
-
queue: partial?.queue,
|
|
106
|
-
flowId: partial?.flowId,
|
|
107
|
-
flowName: partial?.flowName,
|
|
108
|
-
stepName: partial?.stepName,
|
|
109
|
-
stepId: partial?.stepId,
|
|
110
|
-
attempt: partial?.attempt,
|
|
111
|
-
logger: logger2,
|
|
112
|
-
state,
|
|
113
|
-
flow,
|
|
114
|
-
trigger: partial?.trigger,
|
|
115
|
-
awaitConfig: partial?.awaitConfig
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
export function createJobProcessor(handler, queueName) {
|
|
119
|
-
return async function processor(job) {
|
|
120
|
-
const eventMgr = useEventManager();
|
|
121
|
-
const rc = useRuntimeConfig();
|
|
122
|
-
const autoScope = rc?.nvent?.store?.state?.autoScope || "always";
|
|
123
|
-
const providedFlow = job.data?.flowId;
|
|
124
|
-
const flowId = providedFlow || (autoScope === "always" ? randomUUID() : void 0);
|
|
125
|
-
const attempt = (job.attemptsMade || 0) + 1;
|
|
126
|
-
const maxAttempts = job.opts?.attempts || 1;
|
|
127
|
-
const isFinalAttempt = attempt >= maxAttempts;
|
|
128
|
-
const stepRunId = `${String(flowId || job.id)}__${job.name}__attempt-${attempt}`;
|
|
129
|
-
const flowName = job.data?.flowName || "unknown";
|
|
130
|
-
const registry = $useFunctionRegistry();
|
|
131
|
-
const flowRegistry = (registry?.flows || {})[flowName];
|
|
132
|
-
let stepMeta = flowRegistry?.steps?.[job.name];
|
|
133
|
-
if (!stepMeta && flowRegistry?.entry?.step === job.name) {
|
|
134
|
-
stepMeta = flowRegistry?.entry;
|
|
135
|
-
}
|
|
136
|
-
const awaitBefore = stepMeta?.awaitBefore;
|
|
137
|
-
const awaitAfter = stepMeta?.awaitAfter;
|
|
138
|
-
const isAwaitResume = job.data?.awaitResolved === true;
|
|
139
|
-
const awaitData = job.data?.awaitData;
|
|
140
|
-
const awaitPosition = job.data?.awaitPosition;
|
|
141
|
-
const ctx = buildContext({
|
|
142
|
-
jobId: job.id,
|
|
143
|
-
queue: queueName,
|
|
144
|
-
flowId,
|
|
145
|
-
flowName,
|
|
146
|
-
stepName: job.name,
|
|
147
|
-
stepId: stepRunId,
|
|
148
|
-
attempt,
|
|
149
|
-
trigger: isAwaitResume ? awaitData : void 0,
|
|
150
|
-
awaitConfig: awaitBefore || awaitAfter || void 0
|
|
151
|
-
});
|
|
152
|
-
const attemptLogger = {
|
|
153
|
-
log: (level, msg, meta) => {
|
|
154
|
-
const metaObj = meta !== null && meta !== void 0 ? typeof meta === "object" && !Array.isArray(meta) ? meta : { value: meta } : {};
|
|
155
|
-
const enriched = { ...metaObj, stepName: job.name, attempt, stepRunId, flowName };
|
|
156
|
-
ctx.logger.log(level, msg, enriched);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
try {
|
|
160
|
-
await eventMgr.publishBus({
|
|
161
|
-
type: "step.started",
|
|
162
|
-
runId: flowId || "unknown",
|
|
163
|
-
flowName,
|
|
164
|
-
stepName: job.name,
|
|
165
|
-
stepId: stepRunId,
|
|
166
|
-
attempt,
|
|
167
|
-
data: {
|
|
168
|
-
jobId: job.id,
|
|
169
|
-
name: job.name,
|
|
170
|
-
queue: queueName
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
} catch {
|
|
174
|
-
}
|
|
175
|
-
let result;
|
|
176
|
-
try {
|
|
177
|
-
const workerInput = job.data?.input !== void 0 ? job.data.input : job.data;
|
|
178
|
-
result = await handler(workerInput, { ...ctx, logger: attemptLogger });
|
|
179
|
-
} catch (err) {
|
|
180
|
-
logger.error(`[worker] Job failed: ${job.name} (${job.id})`, {
|
|
181
|
-
queue: queueName,
|
|
182
|
-
flowId,
|
|
183
|
-
flowName,
|
|
184
|
-
stepName: job.name,
|
|
185
|
-
error: err?.message || String(err),
|
|
186
|
-
stack: err?.stack
|
|
187
|
-
});
|
|
188
|
-
const willRetry = !isFinalAttempt;
|
|
189
|
-
if (willRetry) {
|
|
190
|
-
try {
|
|
191
|
-
await eventMgr.publishBus({
|
|
192
|
-
type: "step.retry",
|
|
193
|
-
runId: flowId || "unknown",
|
|
194
|
-
flowName,
|
|
195
|
-
stepName: job.name,
|
|
196
|
-
stepId: stepRunId,
|
|
197
|
-
attempt,
|
|
198
|
-
data: {
|
|
199
|
-
stepName: job.name,
|
|
200
|
-
queue: queueName,
|
|
201
|
-
attempt,
|
|
202
|
-
maxAttempts,
|
|
203
|
-
nextAttempt: attempt + 1,
|
|
204
|
-
error: String(err?.message || err),
|
|
205
|
-
stack: err?.stack
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
} catch {
|
|
209
|
-
}
|
|
210
|
-
} else {
|
|
211
|
-
try {
|
|
212
|
-
await eventMgr.publishBus({
|
|
213
|
-
type: "step.failed",
|
|
214
|
-
runId: flowId || "unknown",
|
|
215
|
-
flowName,
|
|
216
|
-
stepName: job.name,
|
|
217
|
-
stepId: stepRunId,
|
|
218
|
-
attempt,
|
|
219
|
-
data: {
|
|
220
|
-
error: String(err?.message || err),
|
|
221
|
-
stack: err?.stack
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
} catch {
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
throw err;
|
|
228
|
-
}
|
|
229
|
-
try {
|
|
230
|
-
const eventMgr2 = useEventManager();
|
|
231
|
-
await eventMgr2.publishBus({
|
|
232
|
-
type: "step.completed",
|
|
233
|
-
runId: flowId || "unknown",
|
|
234
|
-
flowName,
|
|
235
|
-
stepName: job.name,
|
|
236
|
-
stepId: stepRunId,
|
|
237
|
-
attempt,
|
|
238
|
-
data: { result }
|
|
239
|
-
});
|
|
240
|
-
} catch {
|
|
241
|
-
}
|
|
242
|
-
const shouldRegisterAwaitAfter = awaitAfter && (!isAwaitResume || awaitPosition === "before");
|
|
243
|
-
if (shouldRegisterAwaitAfter) {
|
|
244
|
-
try {
|
|
245
|
-
const queue = useQueueAdapter();
|
|
246
|
-
const analyzedFlows = $useAnalyzedFlows();
|
|
247
|
-
const flowDef = analyzedFlows.find((f) => f.id === flowName);
|
|
248
|
-
const analyzedAwaitStep = flowDef?.analyzed?.steps?.[job.name];
|
|
249
|
-
const awaitStepTimeout = analyzedAwaitStep?.stepTimeout;
|
|
250
|
-
await queue.enqueue(queueName, {
|
|
251
|
-
name: SYSTEM_HANDLERS.AWAIT_REGISTER,
|
|
252
|
-
data: {
|
|
253
|
-
flowId: flowId || "unknown",
|
|
254
|
-
flowName,
|
|
255
|
-
stepName: job.name,
|
|
256
|
-
position: "after",
|
|
257
|
-
awaitConfig: awaitAfter,
|
|
258
|
-
input: { ...job.data, result }
|
|
259
|
-
},
|
|
260
|
-
opts: { jobId: `${flowId}__${job.name}__await-register-after`, timeout: awaitStepTimeout }
|
|
261
|
-
});
|
|
262
|
-
} catch (err) {
|
|
263
|
-
logger.error("Failed to register awaitAfter pattern", {
|
|
264
|
-
flowName,
|
|
265
|
-
stepName: job.name,
|
|
266
|
-
error: err.message
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return result;
|
|
271
|
-
};
|
|
272
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import json
|
|
3
|
-
import importlib.util
|
|
4
|
-
import os
|
|
5
|
-
import platform
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def send_message(payload):
|
|
9
|
-
"""Send a JSON line to the parent process.
|
|
10
|
-
|
|
11
|
-
On Unix-like systems, write to the file descriptor provided via env
|
|
12
|
-
NODE_CHANNEL_FD. On Windows, write to stdout.
|
|
13
|
-
"""
|
|
14
|
-
bytes_message = (json.dumps(payload) + "\n").encode("utf-8")
|
|
15
|
-
|
|
16
|
-
if platform.system() == "Windows":
|
|
17
|
-
# On Windows, write to stdout
|
|
18
|
-
sys.stdout.buffer.write(bytes_message)
|
|
19
|
-
sys.stdout.buffer.flush()
|
|
20
|
-
else:
|
|
21
|
-
# On Unix systems, use the provided file descriptor
|
|
22
|
-
fd = int(os.environ["NODE_CHANNEL_FD"]) # expected to be set by parent
|
|
23
|
-
os.write(fd, bytes_message)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
async def run_python_module(file_path: str) -> None:
|
|
27
|
-
try:
|
|
28
|
-
module_dir = os.path.dirname(os.path.abspath(file_path))
|
|
29
|
-
|
|
30
|
-
if module_dir not in sys.path:
|
|
31
|
-
sys.path.insert(0, module_dir)
|
|
32
|
-
|
|
33
|
-
spec = importlib.util.spec_from_file_location(
|
|
34
|
-
os.path.splitext(os.path.basename(file_path))[0], file_path
|
|
35
|
-
)
|
|
36
|
-
if spec is None or spec.loader is None:
|
|
37
|
-
raise ImportError(f"Could not load module from {file_path}")
|
|
38
|
-
|
|
39
|
-
module = importlib.util.module_from_spec(spec)
|
|
40
|
-
# Set a basic package name to allow relative imports from same dir
|
|
41
|
-
module.__package__ = os.path.basename(module_dir)
|
|
42
|
-
spec.loader.exec_module(module)
|
|
43
|
-
|
|
44
|
-
if not hasattr(module, "config"):
|
|
45
|
-
raise AttributeError(f"No 'config' found in module {file_path}")
|
|
46
|
-
|
|
47
|
-
cfg = getattr(module, "config")
|
|
48
|
-
# Remove keys that are not serializable or not needed
|
|
49
|
-
if isinstance(cfg, dict) and "middleware" in cfg:
|
|
50
|
-
del cfg["middleware"]
|
|
51
|
-
|
|
52
|
-
send_message(cfg)
|
|
53
|
-
except Exception as error:
|
|
54
|
-
print("Error running Python module:", str(error), file=sys.stderr)
|
|
55
|
-
sys.exit(1)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if __name__ == "__main__":
|
|
59
|
-
if len(sys.argv) < 2:
|
|
60
|
-
sys.exit(1)
|
|
61
|
-
file_path = sys.argv[1]
|
|
62
|
-
import asyncio
|
|
63
|
-
|
|
64
|
-
asyncio.run(run_python_module(file_path))
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal system handlers for await lifecycle events
|
|
3
|
-
* These handlers run in job context to handle await registration, resolution, and timeout
|
|
4
|
-
*/
|
|
5
|
-
import type { QueueJob } from '../node/runner.js';
|
|
6
|
-
/**
|
|
7
|
-
* System handler for await registration
|
|
8
|
-
* Registers await pattern and calls onAwaitRegister hook
|
|
9
|
-
*/
|
|
10
|
-
export declare function awaitRegisterHandler(job: QueueJob): Promise<{
|
|
11
|
-
success: boolean;
|
|
12
|
-
awaitResult: any;
|
|
13
|
-
}>;
|
|
14
|
-
/**
|
|
15
|
-
* System handler for await resolution
|
|
16
|
-
* Calls onAwaitResolve hook and enqueues the actual step (for awaitBefore)
|
|
17
|
-
*/
|
|
18
|
-
export declare function awaitResolveHandler(job: QueueJob): Promise<{
|
|
19
|
-
success: boolean;
|
|
20
|
-
}>;
|
|
21
|
-
/**
|
|
22
|
-
* System handler for await timeout
|
|
23
|
-
* Calls onAwaitTimeout hook
|
|
24
|
-
*/
|
|
25
|
-
export declare function awaitTimeoutHandler(job: QueueJob): Promise<{
|
|
26
|
-
success: boolean;
|
|
27
|
-
}>;
|