( options: ExecuteWorkflowCoreOptions )
| 311 | } |
| 312 | |
| 313 | export async function executeWorkflowCore( |
| 314 | options: ExecuteWorkflowCoreOptions |
| 315 | ): Promise<ExecutionResult> { |
| 316 | const { |
| 317 | snapshot, |
| 318 | callbacks, |
| 319 | loggingSession, |
| 320 | skipLogCreation, |
| 321 | abortSignal, |
| 322 | includeFileBase64, |
| 323 | base64MaxBytes, |
| 324 | stopAfterBlockId, |
| 325 | runFromBlock, |
| 326 | } = options |
| 327 | const { metadata, workflow, input, workflowVariables, selectedOutputs } = snapshot |
| 328 | const { requestId, workflowId, userId, triggerType, executionId, triggerBlockId, useDraftState } = |
| 329 | metadata |
| 330 | const { onBlockStart, onBlockComplete, onStream, onChildWorkflowInstanceReady } = callbacks |
| 331 | |
| 332 | const providedWorkspaceId = metadata.workspaceId |
| 333 | if (!providedWorkspaceId) { |
| 334 | throw new Error(`Execution metadata missing workspaceId for workflow ${workflowId}`) |
| 335 | } |
| 336 | |
| 337 | let processedInput = input || {} |
| 338 | let deploymentVersionId: string | undefined |
| 339 | let loggingStarted = false |
| 340 | const pendingLifecycleCallbacks = new Set<Promise<void>>() |
| 341 | |
| 342 | const trackLifecycleCallback = (promise: Promise<void>) => { |
| 343 | pendingLifecycleCallbacks.add(promise) |
| 344 | void promise |
| 345 | .finally(() => { |
| 346 | pendingLifecycleCallbacks.delete(promise) |
| 347 | }) |
| 348 | .catch(() => {}) |
| 349 | } |
| 350 | |
| 351 | const waitForLifecycleCallbacks = async () => { |
| 352 | while (pendingLifecycleCallbacks.size > 0) { |
| 353 | await Promise.allSettled([...pendingLifecycleCallbacks]) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | try { |
| 358 | const personalEnvUserId = |
| 359 | metadata.isClientSession && metadata.sessionUserId |
| 360 | ? metadata.sessionUserId |
| 361 | : metadata.workflowUserId |
| 362 | |
| 363 | if (!personalEnvUserId) { |
| 364 | throw new Error('Missing workflowUserId in execution metadata') |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Resolves the workflow state from the override, the draft tables, or the |
| 369 | * deployed snapshot. The async load (draft/deployed) has no data dependency |
| 370 | * on the environment load, so the two are awaited concurrently below. |
no test coverage detected