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:
Adrien de Peretti
2024-10-02 11:54:07 +02:00
committed by GitHub
co-authored by Riqwan Thamir
parent 7ce9121095
commit 02629625ec
5 changed files with 42 additions and 14 deletions
@@ -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"
@@ -1903,7 +1903,7 @@ describe("Workflow composer", function () {
action: "step1",
handlerType: "invoke",
error: expect.objectContaining({
message: "invoke fail",
message: "invoke fail",
}),
})
@@ -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"
@@ -34,7 +38,7 @@ global[OrchestrationUtils.SymbolMedusaWorkflowComposerContext] = null
* @returns The created workflow. You can later execute the workflow by invoking it, then using its `run` method.
*
* @example
* import {
* import {
* createWorkflow,
* WorkflowResponse
* } from "@medusajs/framework/workflows-sdk"
@@ -50,7 +54,7 @@ global[OrchestrationUtils.SymbolMedusaWorkflowComposerContext] = null
* }
*
* const myWorkflow = createWorkflow(
* "my-workflow",
* "my-workflow",
* (input: WorkflowInput) => {
* // Everything here will be executed and resolved later
* // during the execution. Including the data access.
@@ -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,
}
)