Scheduled Jobs in Medusa is a feature that lets developers schedule tasks or cron jobs to automate repetitive tasks. For example, you can push daily updates to an external ERP system or generate weekly sales reports.
The new Scheduled Jobs API will allow you to set up recurring tasks with only a few lines of code with a syntax that is familiar to any JavaScript developer.
Here's a basic example of the API:
// src/jobs/daily-erp-update.ts
import { ProductService, ScheduledJobsConfig, ScheduledJobsArgs } from "@medusajs/medusa"
import ErpService from "../services/erp"
export default async function ({ container }: ScheduledJobsArgs) {
const productService: ProductService = container.resolve("productService")
// Service for interacting with external ERP system
const erpService: ErpService = container.resolve("erpService")
const products = await productService.listAndCount()
await erpService.update(products)
}
export const config: ScheduledJobsConfig = {
name: "daily-erp-update",
schedule: "0 0 * * *" // At 00:00 every night
}
Scheduled Jobs in Medusa is a feature that lets developers schedule tasks or cron jobs to automate repetitive tasks. For example, you can push daily updates to an external ERP system or generate weekly sales reports.
The new Scheduled Jobs API will allow you to set up recurring tasks with only a few lines of code with a syntax that is familiar to any JavaScript developer.
Here's a basic example of the API: