fix: Log error if a scheduled job handler throws (#8164)

CLOSES TRI-19
This commit is contained in:
Stevche Radevski
2024-07-17 12:45:41 +02:00
committed by GitHub
parent 26d600b6db
commit 2ba400f6f1

View File

@@ -5,7 +5,7 @@ import {
} from "@medusajs/workflows-sdk"
import { glob } from "glob"
import logger from "../logger"
import { MedusaError } from "@medusajs/utils"
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
export const registerJobs = async (plugins) => {
await Promise.all(
@@ -50,8 +50,16 @@ const createJob = async ({ config, handler }) => {
`${config.name}-as-step`,
async (stepInput, stepContext) => {
const { container } = stepContext
const res = await handler(container)
return new StepResponse(res, res)
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
try {
const res = await handler(container)
return new StepResponse(res, res)
} catch (error) {
logger.error(
`Scheduled job ${config.name} failed with error: ${error.message}`
)
throw error
}
}
)