|
1
|
import { Table, Prerequisites } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `Redis Workflow Engine Module`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
The Redis Workflow Engine Module uses Redis to track workflow executions and handle their subscribers. In production, it's recommended to use this module. |
|
10
|
|
|
11
|
<Note title="Using Cloud?"> |
|
12
|
|
|
13
|
Our Cloud offering automatically provisions a Redis instance and configures the Redis Workflow Engine Module for you. Learn more in the [Redis](!cloud!/redis) Cloud documentation. |
|
14
|
|
|
15
|
</Note> |
|
16
|
|
|
17
|
--- |
|
18
|
|
|
19
|
## Register the Redis Workflow Engine Module |
|
20
|
|
|
21
|
<Prerequisites items={[ |
|
22
|
{ |
|
23
|
text: "Redis installed and Redis server running", |
|
24
|
link: "https://redis.io/docs/getting-started/installation/" |
|
25
|
} |
|
26
|
]} /> |
|
27
|
|
|
28
|
Add the module into the `modules` property of the exported object in `medusa-config.ts`: |
|
29
|
|
|
30
|
export const highlights = [ |
|
31
|
["8", "redisUrl", "The Redis connection URL."] |
|
32
|
] |
|
33
|
|
|
34
|
```ts title="medusa-config.ts" highlights={highlights} |
|
35
|
module.exports = defineConfig({ |
|
36
|
// ... |
|
37
|
modules: [ |
|
38
|
{ |
|
39
|
resolve: "@medusajs/medusa/workflow-engine-redis", |
|
40
|
options: { |
|
41
|
redis: { |
|
42
|
redisUrl: process.env.WE_REDIS_URL, |
|
43
|
// ...other Redis options |
|
44
|
}, |
|
45
|
}, |
|
46
|
}, |
|
47
|
], |
|
48
|
}) |
|
49
|
``` |
|
50
|
|
|
51
|
### Environment Variables |
|
52
|
|
|
53
|
Make sure to add the following environment variables: |
|
54
|
|
|
55
|
```bash |
|
56
|
WE_REDIS_URL=<YOUR_REDIS_URL> |
|
57
|
``` |
|
58
|
|
|
59
|
### Redis Workflow Engine Module Options |
|
60
|
|
|
61
|
All options below are set within the `redis` property of the module's options object, as shown in the example above. |
|
62
|
|
|
63
|
<Table> |
|
64
|
<Table.Header> |
|
65
|
<Table.Row> |
|
66
|
<Table.HeaderCell> |
|
67
|
Option |
|
68
|
</Table.HeaderCell> |
|
69
|
<Table.HeaderCell> |
|
70
|
Description |
|
71
|
</Table.HeaderCell> |
|
72
|
<Table.HeaderCell> |
|
73
|
Required |
|
74
|
</Table.HeaderCell> |
|
75
|
</Table.Row> |
|
76
|
</Table.Header> |
|
77
|
<Table.Body> |
|
78
|
<Table.Row> |
|
79
|
<Table.Cell> |
|
80
|
|
|
81
|
`url` (Deprecated v2.12.2+, use `redisUrl` instead) |
|
82
|
|
|
83
|
</Table.Cell> |
|
84
|
<Table.Cell> |
|
85
|
|
|
86
|
A string indicating the Redis connection URL. |
|
87
|
|
|
88
|
</Table.Cell> |
|
89
|
<Table.Cell> |
|
90
|
|
|
91
|
No. If not provided, you must provide the `pubsub` option. |
|
92
|
|
|
93
|
</Table.Cell> |
|
94
|
</Table.Row> |
|
95
|
<Table.Row> |
|
96
|
<Table.Cell> |
|
97
|
|
|
98
|
`redisUrl` (v2.12.2+) |
|
99
|
|
|
100
|
</Table.Cell> |
|
101
|
<Table.Cell> |
|
102
|
|
|
103
|
A string indicating the Redis connection URL. |
|
104
|
|
|
105
|
</Table.Cell> |
|
106
|
<Table.Cell> |
|
107
|
|
|
108
|
No. If not provided, you must provide the `pubsub` option. |
|
109
|
|
|
110
|
</Table.Cell> |
|
111
|
</Table.Row> |
|
112
|
<Table.Row> |
|
113
|
<Table.Cell> |
|
114
|
|
|
115
|
`pubsub` |
|
116
|
|
|
117
|
</Table.Cell> |
|
118
|
<Table.Cell> |
|
119
|
|
|
120
|
A connection object having the following properties: |
|
121
|
|
|
122
|
- `url`: A required string indicating the Redis connection URL. |
|
123
|
- `options`: An optional object of Redis options. Refer to the [Redis API Reference](https://redis.github.io/ioredis/index.html#RedisOptions) for details on accepted properties. |
|
124
|
|
|
125
|
</Table.Cell> |
|
126
|
<Table.Cell> |
|
127
|
|
|
128
|
No. If not provided, you must provide the `url` option. |
|
129
|
|
|
130
|
</Table.Cell> |
|
131
|
</Table.Row> |
|
132
|
<Table.Row> |
|
133
|
<Table.Cell> |
|
134
|
|
|
135
|
`queueName` |
|
136
|
|
|
137
|
</Table.Cell> |
|
138
|
<Table.Cell> |
|
139
|
|
|
140
|
The name of the queue used to keep track of retries and timeouts for workflow executions. |
|
141
|
|
|
142
|
Default: `medusa-workflows` |
|
143
|
|
|
144
|
</Table.Cell> |
|
145
|
<Table.Cell> |
|
146
|
|
|
147
|
No |
|
148
|
|
|
149
|
</Table.Cell> |
|
150
|
</Table.Row> |
|
151
|
<Table.Row> |
|
152
|
<Table.Cell> |
|
153
|
|
|
154
|
`jobQueueName` |
|
155
|
|
|
156
|
</Table.Cell> |
|
157
|
<Table.Cell> |
|
158
|
|
|
159
|
The name of the queue used to keep track of retries and timeouts for scheduled jobs. |
|
160
|
|
|
161
|
Default: `medusa-workflows-jobs` |
|
162
|
|
|
163
|
</Table.Cell> |
|
164
|
<Table.Cell> |
|
165
|
|
|
166
|
No |
|
167
|
|
|
168
|
</Table.Cell> |
|
169
|
</Table.Row> |
|
170
|
<Table.Row> |
|
171
|
<Table.Cell> |
|
172
|
|
|
173
|
`options` (deprecated v2.12.2+, use `redisOptions` instead) |
|
174
|
|
|
175
|
</Table.Cell> |
|
176
|
<Table.Cell> |
|
177
|
|
|
178
|
An object of Redis options. Refer to the [Redis API Reference](https://redis.github.io/ioredis/index.html#RedisOptions) for details on accepted properties. |
|
179
|
|
|
180
|
</Table.Cell> |
|
181
|
<Table.Cell> |
|
182
|
|
|
183
|
No |
|
184
|
|
|
185
|
</Table.Cell> |
|
186
|
</Table.Row> |
|
187
|
<Table.Row> |
|
188
|
<Table.Cell> |
|
189
|
|
|
190
|
`redisOptions` (v2.12.2+) |
|
191
|
|
|
192
|
</Table.Cell> |
|
193
|
<Table.Cell> |
|
194
|
|
|
195
|
An object of Redis options. Refer to the [Redis API Reference](https://redis.github.io/ioredis/index.html#RedisOptions) for details on accepted properties. |
|
196
|
|
|
197
|
</Table.Cell> |
|
198
|
<Table.Cell> |
|
199
|
|
|
200
|
No |
|
201
|
|
|
202
|
</Table.Cell> |
|
203
|
</Table.Row> |
|
204
|
<Table.Row> |
|
205
|
<Table.Cell> |
|
206
|
|
|
207
|
`queueOptions` (v2.12.2+) |
|
208
|
|
|
209
|
</Table.Cell> |
|
210
|
<Table.Cell> |
|
211
|
|
|
212
|
An object of options to pass to all BullMQ instances. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.QueueOptions.html) for allowed properties. |
|
213
|
|
|
214
|
</Table.Cell> |
|
215
|
<Table.Cell> |
|
216
|
|
|
217
|
No |
|
218
|
|
|
219
|
</Table.Cell> |
|
220
|
</Table.Row> |
|
221
|
<Table.Row> |
|
222
|
<Table.Cell> |
|
223
|
|
|
224
|
`workerOptions` (v2.12.2+) |
|
225
|
|
|
226
|
</Table.Cell> |
|
227
|
<Table.Cell> |
|
228
|
|
|
229
|
An object of options to pass to all BullMQ worker instances. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.WorkerOptions.html) for allowed properties. |
|
230
|
|
|
231
|
You can instead set options per worker using the `mainWorkerOptions`, `jobWorkerOptions`, and `cleanerWorkerOptions` options. |
|
232
|
|
|
233
|
</Table.Cell> |
|
234
|
<Table.Cell> |
|
235
|
|
|
236
|
No |
|
237
|
|
|
238
|
</Table.Cell> |
|
239
|
</Table.Row> |
|
240
|
<Table.Row> |
|
241
|
<Table.Cell> |
|
242
|
|
|
243
|
`mainQueueOptions` (v2.12.2+) |
|
244
|
|
|
245
|
</Table.Cell> |
|
246
|
<Table.Cell> |
|
247
|
|
|
248
|
An object of options to pass to the main BullMQ queue instance for workflows. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.QueueOptions.html) for allowed properties. |
|
249
|
|
|
250
|
</Table.Cell> |
|
251
|
<Table.Cell> |
|
252
|
|
|
253
|
No |
|
254
|
|
|
255
|
</Table.Cell> |
|
256
|
</Table.Row> |
|
257
|
<Table.Row> |
|
258
|
<Table.Cell> |
|
259
|
|
|
260
|
`mainWorkerOptions` (v2.12.2+) |
|
261
|
|
|
262
|
</Table.Cell> |
|
263
|
<Table.Cell> |
|
264
|
|
|
265
|
An object of options to pass to the main BullMQ worker instance for workflows. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.WorkerOptions.html) for allowed properties. |
|
266
|
|
|
267
|
</Table.Cell> |
|
268
|
<Table.Cell> |
|
269
|
|
|
270
|
No |
|
271
|
|
|
272
|
</Table.Cell> |
|
273
|
</Table.Row> |
|
274
|
<Table.Row> |
|
275
|
<Table.Cell> |
|
276
|
|
|
277
|
`jobQueueOptions` (v2.12.2+) |
|
278
|
|
|
279
|
</Table.Cell> |
|
280
|
<Table.Cell> |
|
281
|
|
|
282
|
An object of options to pass to the main BullMQ workflow queue instance for scheduled jobs. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.QueueOptions.html) for allowed properties. |
|
283
|
|
|
284
|
</Table.Cell> |
|
285
|
<Table.Cell> |
|
286
|
|
|
287
|
No |
|
288
|
|
|
289
|
</Table.Cell> |
|
290
|
</Table.Row> |
|
291
|
<Table.Row> |
|
292
|
<Table.Cell> |
|
293
|
|
|
294
|
`jobWorkerOptions` (v2.12.2+) |
|
295
|
|
|
296
|
</Table.Cell> |
|
297
|
<Table.Cell> |
|
298
|
|
|
299
|
An object of options to pass to the main BullMQ workflow worker instance for scheduled jobs. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.WorkerOptions.html) for allowed properties. |
|
300
|
|
|
301
|
</Table.Cell> |
|
302
|
<Table.Cell> |
|
303
|
|
|
304
|
No |
|
305
|
|
|
306
|
</Table.Cell> |
|
307
|
</Table.Row> |
|
308
|
<Table.Row> |
|
309
|
<Table.Cell> |
|
310
|
|
|
311
|
`cleanerQueueOptions` (v2.12.2+) |
|
312
|
|
|
313
|
</Table.Cell> |
|
314
|
<Table.Cell> |
|
315
|
|
|
316
|
An object of options to pass to the BullMQ cleaner queue instance. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.QueueOptions.html) for allowed properties. |
|
317
|
|
|
318
|
</Table.Cell> |
|
319
|
<Table.Cell> |
|
320
|
|
|
321
|
No |
|
322
|
|
|
323
|
</Table.Cell> |
|
324
|
</Table.Row> |
|
325
|
<Table.Row> |
|
326
|
<Table.Cell> |
|
327
|
|
|
328
|
`cleanerWorkerOptions` (v2.12.2+) |
|
329
|
|
|
330
|
</Table.Cell> |
|
331
|
<Table.Cell> |
|
332
|
|
|
333
|
An object of options to pass to the BullMQ cleaner worker instance. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v5.WorkerOptions.html) for allowed properties. |
|
334
|
|
|
335
|
</Table.Cell> |
|
336
|
<Table.Cell> |
|
337
|
|
|
338
|
No |
|
339
|
|
|
340
|
</Table.Cell> |
|
341
|
</Table.Row> |
|
342
|
</Table.Body> |
|
343
|
</Table> |
|
344
|
|
|
345
|
## Test the Module |
|
346
|
|
|
347
|
To test the module, start the Medusa application: |
|
348
|
|
|
349
|
```bash npm2yarn |
|
350
|
npm run dev |
|
351
|
``` |
|
352
|
|
|
353
|
You'll see the following message in the terminal's logs: |
|
354
|
|
|
355
|
```bash noCopy noReport |
|
356
|
Connection to Redis in module 'workflow-engine-redis' established |
|
357
|
``` |