-
|
Hi, I am currently porting our jobs from ActiveJob to using Sidekiq directly, but we have a need in one case to track the specific queue a job was popped from when it was performed. ActiveJob has the My backup plan is to use server middleware, which does accurate receive the overridden queue name: class SidekiqServerMiddleware
include Sidekiq::ServerMiddleware
def call(job, _msg, queue)
job.instance_variable_set(:@queue_name, queue)
yield
end
endThis works, but I cannot get this middleware to apply in testing. Adding it to the Is there a better way? Currently on Sidekiq 7.3.9. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
The issue is that the queue is orthogonal to the job functionality. It is a breach of encapsulation for the job to look at what queue it was placed into. By adding this type of logic to the job, you're making it harder to test and your code more brittle. Does that make sense? Your middleware approach is correct. It should work if you use the inline test mode? |
Beta Was this translation helpful? Give feedback.
The issue was using
sync: truein thesetcall in the test, (which I had added earlier before learning aboutSidekiq::Testing.server_middleware,) after seeing it in theSetterclass. After removing thesync: true, the middleware is applied as expected in both fake and inline modes.