How to work with CLS inside a bull queue #178
-
I'd like to access CLS context within a consumer class, i.e. a class decorated with @Processor. We are using
The setup I run in the UseCls decorator is the same for each method. Ideally, I'd like to avoid duplicating this everywhere. My initial idea was to use applyDecorators to compose the
Am I missing anything obvious here that would enable me to reduce the amount of boilerplate I'm need to write to access CLS in queues? I'm new to nestjs, working with decorators, and using cls in general, so it's very likely I'm doing something wrong. My understanding is that since my usage is outside of a web request my options here might be limited. Any input or ideas would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, your idea is generally correct, and if you explicitly cast The issue here is that the I'll try to investigate this more on my end and get back with other possible solutions. Btw, if you don't want to repeat a decorator on each method of a class, you might try my |
Beta Was this translation helpful? Give feedback.
Hi, your idea is generally correct, and if you explicitly cast
UseCls
toany
, then it should work as expected at runtime.EDIT: The recommended solution has been added to the docs.
The issue here is that the
UseCls
decorator doesn't, for some reason, satisfy the general decorator interfaces that Nest's method expects. Likely becaue theUseCls
decorator is generic and uses a bit of typescript magic to be type-safe according to the function on which you use it.I'll try to investigate this more on my end and get back with other possible solutions.
Btw, if you don't want to repeat a decorator on each method of a class, you might try my
decorate-all
npm package, although you might bump into t…