feat: Workflow engine modules (#6128)
This commit is contained in:
committed by
GitHub
parent
d85fee42ee
commit
302323916b
@@ -1,4 +1,11 @@
|
||||
import { resolveValue, StepResponse } from "./helpers"
|
||||
import {
|
||||
TransactionStepsDefinition,
|
||||
WorkflowManager,
|
||||
} from "@medusajs/orchestration"
|
||||
import { OrchestrationUtils, isString } from "@medusajs/utils"
|
||||
import { ulid } from "ulid"
|
||||
import { StepResponse, resolveValue } from "./helpers"
|
||||
import { proxify } from "./helpers/proxy"
|
||||
import {
|
||||
CreateWorkflowComposerContext,
|
||||
StepExecutionContext,
|
||||
@@ -6,9 +13,6 @@ import {
|
||||
StepFunctionResult,
|
||||
WorkflowData,
|
||||
} from "./type"
|
||||
import { proxify } from "./helpers/proxy"
|
||||
import { TransactionStepsDefinition } from "@medusajs/orchestration"
|
||||
import { isString, OrchestrationUtils } from "@medusajs/utils"
|
||||
|
||||
/**
|
||||
* The type of invocation function passed to a step.
|
||||
@@ -166,19 +170,37 @@ function applyStep<
|
||||
: undefined,
|
||||
}
|
||||
|
||||
stepConfig!.noCompensation = !compensateFn
|
||||
stepConfig.uuid = ulid()
|
||||
stepConfig.noCompensation = !compensateFn
|
||||
|
||||
this.flow.addAction(stepName, stepConfig)
|
||||
this.handlers.set(stepName, handler)
|
||||
|
||||
if (!this.handlers.has(stepName)) {
|
||||
this.handlers.set(stepName, handler)
|
||||
}
|
||||
|
||||
const ret = {
|
||||
__type: OrchestrationUtils.SymbolWorkflowStep,
|
||||
__step__: stepName,
|
||||
config: (config: Pick<TransactionStepsDefinition, "maxRetries">) => {
|
||||
this.flow.replaceAction(stepName, stepName, {
|
||||
config: (
|
||||
localConfig: { name?: string } & Omit<
|
||||
TransactionStepsDefinition,
|
||||
"next" | "uuid" | "action"
|
||||
>
|
||||
) => {
|
||||
const newStepName = localConfig.name ?? stepName
|
||||
|
||||
delete localConfig.name
|
||||
|
||||
this.handlers.set(newStepName, handler)
|
||||
|
||||
this.flow.replaceAction(stepConfig.uuid!, newStepName, {
|
||||
...stepConfig,
|
||||
...config,
|
||||
...localConfig,
|
||||
})
|
||||
|
||||
WorkflowManager.update(this.workflowId, this.flow, this.handlers)
|
||||
|
||||
return proxify(ret)
|
||||
},
|
||||
}
|
||||
@@ -241,11 +263,14 @@ export function createStep<
|
||||
TInvokeResultCompensateInput
|
||||
>(
|
||||
/**
|
||||
* The name of the step or its configuration (currently support maxRetries).
|
||||
* The name of the step or its configuration.
|
||||
*/
|
||||
nameOrConfig:
|
||||
| string
|
||||
| ({ name: string } & Pick<TransactionStepsDefinition, "maxRetries">),
|
||||
| ({ name: string } & Omit<
|
||||
TransactionStepsDefinition,
|
||||
"next" | "uuid" | "action"
|
||||
>),
|
||||
/**
|
||||
* An invocation function that will be executed when the workflow is executed. The function must return an instance of {@link StepResponse}. The constructor of {@link StepResponse}
|
||||
* accepts the output of the step as a first argument, and optionally as a second argument the data to be passed to the compensation function as a parameter.
|
||||
|
||||
Reference in New Issue
Block a user