feat(orchestration): Provide hint in workflows error (#9400)
* feat(orchestration): Provide hint in workflows error * remove log * fix tests * improve stack * fix type * formatting --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
co-authored by
Riqwan Thamir
parent
7ce9121095
commit
02629625ec
@@ -549,6 +549,16 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
|
||||
step.changeState(TransactionStepState.TIMEOUT)
|
||||
|
||||
if (error?.stack) {
|
||||
const workflowId = transaction.modelId
|
||||
const stepAction = step.definition.action
|
||||
const sourcePath = transaction.getFlow().metadata?.sourcePath
|
||||
const sourceStack = sourcePath
|
||||
? `\n⮑ \sat ${sourcePath}: [${workflowId} -> ${stepAction} (${TransactionHandlerType.INVOKE})]`
|
||||
: `\n⮑ \sat [${workflowId} -> ${stepAction} (${TransactionHandlerType.INVOKE})]`
|
||||
error.stack += sourceStack
|
||||
}
|
||||
|
||||
transaction.addError(
|
||||
step.definition.action!,
|
||||
TransactionHandlerType.INVOKE,
|
||||
@@ -602,13 +612,21 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
step.changeStatus(TransactionStepStatus.PERMANENT_FAILURE)
|
||||
|
||||
if (!isTimeout) {
|
||||
transaction.addError(
|
||||
step.definition.action!,
|
||||
step.isCompensating()
|
||||
const handlerType = step.isCompensating()
|
||||
? TransactionHandlerType.COMPENSATE
|
||||
: TransactionHandlerType.INVOKE,
|
||||
error
|
||||
)
|
||||
: TransactionHandlerType.INVOKE
|
||||
|
||||
if (error?.stack) {
|
||||
const workflowId = transaction.modelId
|
||||
const stepAction = step.definition.action
|
||||
const sourcePath = transaction.getFlow().metadata?.sourcePath
|
||||
const sourceStack = sourcePath
|
||||
? `\n⮑ \sat ${sourcePath}: [${workflowId} -> ${stepAction} (${TransactionHandlerType.INVOKE})]`
|
||||
: `\n⮑ \sat [${workflowId} -> ${stepAction} (${TransactionHandlerType.INVOKE})]`
|
||||
error.stack += sourceStack
|
||||
}
|
||||
|
||||
transaction.addError(step.definition.action!, handlerType, error)
|
||||
}
|
||||
|
||||
if (!step.isCompensating()) {
|
||||
|
||||
@@ -243,6 +243,7 @@ export type TransactionFlow = {
|
||||
metadata?: {
|
||||
eventGroupId?: string
|
||||
parentIdempotencyKey?: string
|
||||
sourcePath?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
hasAsyncSteps: boolean
|
||||
|
||||
@@ -44,6 +44,7 @@ function createContextualWorkflowRunner<
|
||||
dataPreparation?: (data: TData) => Promise<unknown>
|
||||
options?: {
|
||||
wrappedInput?: boolean
|
||||
sourcePath?: string
|
||||
}
|
||||
container?: LoadedModule[] | MedusaContainer
|
||||
}): Omit<
|
||||
@@ -93,6 +94,7 @@ function createContextualWorkflowRunner<
|
||||
const flowMetadata = {
|
||||
eventGroupId,
|
||||
parentStepIdempotencyKey,
|
||||
sourcePath: options?.sourcePath,
|
||||
}
|
||||
|
||||
const args = [
|
||||
@@ -334,6 +336,7 @@ export const exportWorkflow = <TData = unknown, TResult = unknown>(
|
||||
dataPreparation?: (data: TData) => Promise<unknown>,
|
||||
options?: {
|
||||
wrappedInput?: boolean
|
||||
sourcePath?: string
|
||||
}
|
||||
): MainExportedWorkflow<TData, TResult> => {
|
||||
function exportedWorkflow<
|
||||
|
||||
@@ -6,19 +6,19 @@ import {
|
||||
} from "@medusajs/orchestration"
|
||||
import { IEventBusModuleService } from "@medusajs/types"
|
||||
import {
|
||||
Modules,
|
||||
composeMessage,
|
||||
createMedusaContainer,
|
||||
Modules,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import {
|
||||
StepResponse,
|
||||
WorkflowResponse,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
StepResponse,
|
||||
transform,
|
||||
WorkflowResponse,
|
||||
} from ".."
|
||||
import { MedusaWorkflow } from "../../../medusa-workflow"
|
||||
import { createHook } from "../create-hook"
|
||||
|
||||
@@ -4,7 +4,11 @@ import {
|
||||
WorkflowManager,
|
||||
} from "@medusajs/orchestration"
|
||||
import { LoadedModule, MedusaContainer } from "@medusajs/types"
|
||||
import { OrchestrationUtils, isString } from "@medusajs/utils"
|
||||
import {
|
||||
getCallerFilePath,
|
||||
isString,
|
||||
OrchestrationUtils,
|
||||
} from "@medusajs/utils"
|
||||
import { ulid } from "ulid"
|
||||
import { exportWorkflow } from "../../helper"
|
||||
import { createStep } from "./create-step"
|
||||
@@ -92,6 +96,7 @@ export function createWorkflow<TData, TResult, THooks extends any[]>(
|
||||
input: WorkflowData<TData>
|
||||
) => void | WorkflowResponse<TResult, THooks>
|
||||
): ReturnWorkflow<TData, TResult, THooks> {
|
||||
const fileSourcePath = getCallerFilePath() as string
|
||||
const name = isString(nameOrConfig) ? nameOrConfig : nameOrConfig.name
|
||||
const options = isString(nameOrConfig) ? {} : nameOrConfig
|
||||
|
||||
@@ -153,6 +158,7 @@ export function createWorkflow<TData, TResult, THooks extends any[]>(
|
||||
undefined,
|
||||
{
|
||||
wrappedInput: true,
|
||||
sourcePath: fileSourcePath,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user