Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix incorrect RequestContext serialization method #3365

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/docs/guides/developer-guide/worker-job-queue/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ export class ProductVideoPlugin {}

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
service methods that you may be using inside your `process` function. However, the `RequestContext` object itself is not serializable,
so it cannot be passed directly to the `JobQueue.add()` method. Instead, you can serialize the `RequestContext` using the [`RequestContext.serialize()`
method](/reference/typescript-api/request/request-context/#serialize), and then deserialize it in the `process` function using the static `deserialize` method:
so it cannot be passed directly to the `JobQueue.add()` method. Instead, you can serialize the `RequestContext` using the [`ctx.serialize()` method](/reference/typescript-api/request/request-context/#serialize),
and then deserialize it in the `process` function using the static `deserialize` method.


```ts
import { Injectable, OnModuleInit } from '@nestjs/common';
Expand Down Expand Up @@ -358,7 +359,7 @@ class ProductExportService implements OnModuleInit {

exportAllProducts(ctx: RequestContext) {
// highlight-next-line
return this.jobQueue.add({ ctx: RequestContext.serialize(ctx) });
return this.jobQueue.add({ ctx: ctx.serialize() });
}
}
```
Expand Down Expand Up @@ -468,7 +469,7 @@ class ProductExportService implements OnModuleInit {
}

exportAllProducts(ctx: RequestContext) {
return this.jobQueue.add({ ctx: RequestContext.serialize(ctx) });
return this.jobQueue.add({ ctx: ctx.serialize() });
}
}
```
Expand Down