1 import NotRunning from "../_sections/scheduled-jobs/not-running.mdx"
2 import NotRunningWorkerMode from "../_sections/scheduled-jobs/not-running-worker-mode.mdx"
3
4 export const metadata = {
5 title: `Scheduled Job Not Running on Schedule`,
6 }
7
8 # {metadata.title}
9
10 This troubleshooting guide helps you troubleshoot issues when a scheduled job in your Medusa application is not running, or running at unexpected times.
11
12 ## Confirm Job is Set Up Correctly
13
14 Make sure that the scheduled job is set up correctly in your Medusa application. Check the following:
15
16 1. The job is created under the `src/jobs` directory.
17 2. The job exports an asynchronous function that performs the task. For example:
18
19 ```ts title="src/jobs/hello-world.ts"
20 import { MedusaContainer } from "@medusajs/framework/types"
21 import {
22 ContainerRegistrationKeys,
23 } from "@medusajs/framework/utils"
24
25 export default async function greetingJob(container: MedusaContainer) {
26 const logger = container.resolve(
27 ContainerRegistrationKeys.LOGGER
28 )
29
30 logger.info("Greeting!")
31 }
32 ```
33
34 3. The job exports a `config` object that has the following properties:
35 - `name`: A unique name for the job.
36 - `schedule`: A string that holds a [cron expression](https://crontab.guru/) or an `interval` indicating the schedule to run the job.
37
38 For example:
39
40 ```ts title="src/jobs/hello-world.ts"
41 export const config = {
42 name: "greeting-every-minute",
43 schedule: "* * * * *",
44 }
45 ```
46
47 ---
48
49 ## Job Not Running on Schedule
50
51 <NotRunning />
52
53 ---
54
55 ## Confirm Worker Mode is Set Up Correctly
56
57 <NotRunningWorkerMode />