|
@@ -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
|
|
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,
|
|
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
|
|
```ts
|
|
|
import { Injectable, OnModuleInit } from '@nestjs/common';
|
|
import { Injectable, OnModuleInit } from '@nestjs/common';
|
|
@@ -358,7 +359,7 @@ class ProductExportService implements OnModuleInit {
|
|
|
|
|
|
|
|
exportAllProducts(ctx: RequestContext) {
|
|
exportAllProducts(ctx: RequestContext) {
|
|
|
// highlight-next-line
|
|
// highlight-next-line
|
|
|
- return this.jobQueue.add({ ctx: RequestContext.serialize(ctx) });
|
|
|
|
|
|
|
+ return this.jobQueue.add({ ctx: ctx.serialize() });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
@@ -468,7 +469,7 @@ class ProductExportService implements OnModuleInit {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
exportAllProducts(ctx: RequestContext) {
|
|
exportAllProducts(ctx: RequestContext) {
|
|
|
- return this.jobQueue.add({ ctx: RequestContext.serialize(ctx) });
|
|
|
|
|
|
|
+ return this.jobQueue.add({ ctx: ctx.serialize() });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|