diff --git a/packages/core/src/worker/types.ts b/packages/core/src/worker/types.ts index 8b7fec145d..c07a21b5a9 100644 --- a/packages/core/src/worker/types.ts +++ b/packages/core/src/worker/types.ts @@ -5,7 +5,7 @@ * * @example * ```TypeScript - * export class ReindexMessage extends WorkerMessage<{ ctx: RequestContext }, boolean> { + * export class ReindexMessage extends WorkerMessage<{ ctx: SerializedRequestContext }, boolean> { * static readonly pattern = 'Reindex'; * } * @@ -15,7 +15,10 @@ * constructor(private workerService: WorkerService) {} * * reindex(ctx: RequestContext): Observable> { - * return this.workerService.send(new ReindexMessage({ ctx })) + * // If you need to send the RequestContext object to the worker, + * // be sure to send a serialized version to avoid errors. + * const serializedCtx = ctx.serialize(); + * return this.workerService.send(new ReindexMessage({ ctx: serializedCtx })) * } * } * @@ -23,7 +26,10 @@ * class MyController { * * \@MessagePattern(ReindexMessage.pattern) - * reindex({ ctx: rawContext }: ReindexMessage['data']): Observable { + * reindex({ ctx: serializedCtx }: ReindexMessage['data']): Observable { + * // Convert the SerializedRequestContext back into a regular + * // RequestContext object + * const ctx = RequestContext.deserialize(serializedCtx); * // ... some long-running workload * } * }