fix(orchestrator): save checkpoint before async step (#12138)
This commit is contained in:
committed by
GitHub
parent
07252691c5
commit
31abba8cde
@@ -15,6 +15,7 @@ import {
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { WorkflowsModuleService } from "@services"
|
||||
import { asFunction } from "awilix"
|
||||
import { setTimeout as setTimeoutSync } from "timers"
|
||||
import { setTimeout as setTimeoutPromise } from "timers/promises"
|
||||
import "../__fixtures__"
|
||||
import {
|
||||
@@ -28,7 +29,6 @@ import {
|
||||
workflowEventGroupIdStep1Mock,
|
||||
workflowEventGroupIdStep2Mock,
|
||||
} from "../__fixtures__/workflow_event_group_id"
|
||||
import { setTimeout as setTimeoutSync } from "timers"
|
||||
import { createScheduled } from "../__fixtures__/workflow_scheduled"
|
||||
|
||||
jest.setTimeout(300000)
|
||||
@@ -97,9 +97,9 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
|
||||
await workflowOrcModule.run(eventGroupWorkflowId, {
|
||||
input: {},
|
||||
transactionId: "transaction_id",
|
||||
context: {
|
||||
eventGroupId,
|
||||
transactionId: "transaction_id",
|
||||
},
|
||||
throwOnError: true,
|
||||
})
|
||||
@@ -126,9 +126,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
it("should execute an async workflow keeping track of the event group id that has been auto generated", async () => {
|
||||
await workflowOrcModule.run(eventGroupWorkflowId, {
|
||||
input: {},
|
||||
context: {
|
||||
transactionId: "transaction_id_2",
|
||||
},
|
||||
transactionId: "transaction_id_2",
|
||||
throwOnError: true,
|
||||
})
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ export class WorkflowOrchestratorService {
|
||||
let { throwOnError, context } = options ?? {}
|
||||
throwOnError ??= true
|
||||
context ??= {}
|
||||
context.transactionId ??= transactionId ?? ulid()
|
||||
context.transactionId = transactionId ?? ulid()
|
||||
|
||||
const workflowId = isString(workflowIdOrWorkflow)
|
||||
? workflowIdOrWorkflow
|
||||
|
||||
@@ -83,24 +83,26 @@ export class WorkflowsModuleService<
|
||||
> = {},
|
||||
@MedusaContext() context: Context = {}
|
||||
) {
|
||||
options ??= {}
|
||||
const options_ = JSON.parse(JSON.stringify(options ?? {}))
|
||||
|
||||
const {
|
||||
manager,
|
||||
transactionManager,
|
||||
preventReleaseEvents,
|
||||
transactionId,
|
||||
...restContext
|
||||
} = context
|
||||
|
||||
options.context ??= restContext
|
||||
options.context.preventReleaseEvents ??=
|
||||
!!options.context.parentStepIdempotencyKey
|
||||
delete options.context.parentStepIdempotencyKey
|
||||
options_.context ??= restContext
|
||||
options_.context.preventReleaseEvents ??=
|
||||
!!options_.context.parentStepIdempotencyKey
|
||||
delete options_.context.parentStepIdempotencyKey
|
||||
|
||||
const ret = await this.workflowOrchestratorService_.run<
|
||||
TWorkflow extends ReturnWorkflow<any, any, any>
|
||||
? UnwrapWorkflowInputDataType<TWorkflow>
|
||||
: unknown
|
||||
>(workflowIdOrWorkflow, options)
|
||||
>(workflowIdOrWorkflow, options_)
|
||||
|
||||
return ret as any
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ export class WorkflowOrchestratorService {
|
||||
|
||||
throwOnError ??= true
|
||||
context ??= {}
|
||||
context.transactionId ??= transactionId ?? ulid()
|
||||
context.transactionId = transactionId ?? ulid()
|
||||
|
||||
const workflowId = isString(workflowIdOrWorkflow)
|
||||
? workflowIdOrWorkflow
|
||||
|
||||
@@ -95,24 +95,26 @@ export class WorkflowsModuleService<
|
||||
> = {},
|
||||
@MedusaContext() context: Context = {}
|
||||
) {
|
||||
options ??= {}
|
||||
const options_ = JSON.parse(JSON.stringify(options ?? {}))
|
||||
|
||||
const {
|
||||
manager,
|
||||
transactionManager,
|
||||
preventReleaseEvents,
|
||||
transactionId,
|
||||
...restContext
|
||||
} = context
|
||||
|
||||
options.context ??= restContext
|
||||
options.context.preventReleaseEvents ??=
|
||||
!!options.context.parentStepIdempotencyKey
|
||||
delete options.context.parentStepIdempotencyKey
|
||||
options_.context ??= restContext
|
||||
options_.context.preventReleaseEvents ??=
|
||||
!!options_.context.parentStepIdempotencyKey
|
||||
delete options_.context.parentStepIdempotencyKey
|
||||
|
||||
const ret = await this.workflowOrchestratorService_.run<
|
||||
TWorkflow extends ReturnWorkflow<any, any, any>
|
||||
? UnwrapWorkflowInputDataType<TWorkflow>
|
||||
: unknown
|
||||
>(workflowIdOrWorkflow, options)
|
||||
>(workflowIdOrWorkflow, options_)
|
||||
|
||||
return ret as any
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user