|
1
|
If your scheduled job isn't running at all, it may be because your Medusa application is not running in [worker mode](!docs!/learn/production/worker-mode). |
|
2
|
|
|
3
|
<Note> |
|
4
|
|
|
5
|
If you're a Cloud user and this issue is happening on your deployed Medusa application, contact support for assistance. |
|
6
|
|
|
7
|
</Note> |
|
8
|
|
|
9
|
### Why this Happens |
|
10
|
|
|
11
|
By default, the Medusa application runs both the server, which handles all incoming requests, and the worker, which processes background tasks, in a single process. |
|
12
|
|
|
13
|
In production, you should deploy two separate instances of your Medusa application: one for the server and one for the worker. |
|
14
|
|
|
15
|
However, if you deploy only a server instance, or if you accidentally set the worker mode to `server`, the scheduled jobs won't run because there is no worker process to handle them. |
|
16
|
|
|
17
|
### How to Fix it |
|
18
|
|
|
19
|
#### Deploy a Worker Instance |
|
20
|
|
|
21
|
If you haven't deployed a worker instance of your Medusa application, do so by following the steps in the [Worker Mode of Medusa Instance](!docs!/learn/production/worker-mode) guide. |
|
22
|
|
|
23
|
For example, you should have the following configuration in your `medusa-config.ts` file: |
|
24
|
|
|
25
|
```ts title="medusa-config.ts" |
|
26
|
module.exports = defineConfig({ |
|
27
|
projectConfig: { |
|
28
|
workerMode: process.env.WORKER_MODE || "shared", |
|
29
|
// ... |
|
30
|
}, |
|
31
|
// ... |
|
32
|
}) |
|
33
|
``` |
|
34
|
|
|
35
|
In your deployed server Medusa instance, set `WORKER_MODE` to `server`, and in your deployed worker Medusa instance, set `WORKER_MODE` to `worker`. |
|
36
|
|
|
37
|
#### Set the Correct Worker Mode |
|
38
|
|
|
39
|
If this issue is happening locally, ensure that you set the correct worker mode in your `medusa-config.ts` file. |
|
40
|
|
|
41
|
When running the server locally, either don't set the `workerMode` configuration or set it to `shared` in `medusa-config.ts`: |
|
42
|
|
|
43
|
```ts title="medusa-config.ts" |
|
44
|
module.exports = defineConfig({ |
|
45
|
projectConfig: { |
|
46
|
workerMode: "shared", // or don't set it at all |
|
47
|
// ... |
|
48
|
}, |
|
49
|
// ... |
|
50
|
}) |
|
51
|
``` |
|
52
|
|
|
53
|
#### Additional Resources |
|
54
|
|
|
55
|
- [Worker Mode](!docs!/learn/production/worker-mode) |