fix: Remove scheduled workflows if they no longer exist when executed (#7673)

This commit is contained in:
Stevche Radevski
2024-06-11 12:57:25 +02:00
committed by GitHub
parent 8e2a42b786
commit 3d72002c28
7 changed files with 103 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import {
isString,
MedusaContext,
MedusaContextType,
MedusaError,
MedusaModuleType,
} from "@medusajs/utils"
import { asValue } from "awilix"
@@ -51,7 +52,10 @@ export class LocalWorkflow {
) {
const globalWorkflow = WorkflowManager.getWorkflow(workflowId)
if (!globalWorkflow) {
throw new Error(`Workflow with id "${workflowId}" not found.`)
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Workflow with id "${workflowId}" not found.`
)
}
this.flow = new OrchestratorBuilder(globalWorkflow.flow_)

View File

@@ -11,6 +11,7 @@ import {
TransactionStepsDefinition,
} from "../transaction"
import { WorkflowScheduler } from "./scheduler"
import { MedusaError } from "@medusajs/utils"
export interface WorkflowDefinition {
id: string
@@ -78,7 +79,10 @@ export class WorkflowManager {
static getTransactionDefinition(workflowId): OrchestratorBuilder {
if (!WorkflowManager.workflows.has(workflowId)) {
throw new Error(`Workflow with id "${workflowId}" not found.`)
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Workflow with id "${workflowId}" not found.`
)
}
const workflow = WorkflowManager.workflows.get(workflowId)!