You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/guides/developer-guide/worker-job-queue/index.mdx
+54-1Lines changed: 54 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -324,7 +324,7 @@ export class ProductVideoPlugin {}
324
324
325
325
### Passing the RequestContext
326
326
327
-
It is common to need to pass the [RequestContext object](/reference/typescript-api/request/request-context) to the `process` function of a job, since `ctx` is required by many Vendure
327
+
Sometimes you need to pass the [RequestContext object](/reference/typescript-api/request/request-context) to the `process` function of a job, since `ctx` is required by many Vendure
328
328
service methods that you may be using inside your `process` function. However, the `RequestContext` object itself is not serializable,
329
329
so it cannot be passed directly to the `JobQueue.add()` method. Instead, you can serialize the `RequestContext` using the [`RequestContext.serialize()`
330
330
method](/reference/typescript-api/request/request-context/#serialize), and then deserialize it in the `process` function using the static `deserialize` method:
@@ -363,6 +363,59 @@ class ProductExportService implements OnModuleInit {
363
363
}
364
364
```
365
365
366
+
:::warning
367
+
Serializing the RequestContext should be done with caution, since it is a relatively large object and will significantly increase the size of the job data.
368
+
369
+
In cases where the job is created in large quantities (hundreds or thousands of jobs per day), this can lead to performance issues. Especially
370
+
when using the [BullMQJobQueuePlugin](/reference/core-plugins/job-queue-plugin/bull-mqjob-queue-plugin/), which stores the job data in Redis, the
371
+
size of the job data can lead to too much memory usage which can cause the Redis server to crash.
372
+
:::
373
+
374
+
Instead of serializing the entire RequestContext, consider passing only the necessary data you need and then reconstructing the RequestContext in the `process` function:
0 commit comments