Draft: fix: unset SidekiqStatus on job failure
Changes
Fixed lib/gitlab/sidekiq_status/server_middleware.rb
- Replaced the current implementation with a
begin-ensureblock pattern - The
ensureblock guarantees thatSidekiqStatus.unset(job['jid'])is always called, even when exceptions are raised - This follows the same pattern used in other middleware like
BatchLoader - The implementation is now cleaner and more concise (4 lines instead of 6)
Added test coverage in spec/lib/gitlab/sidekiq_status/server_middleware_spec.rb
- Added a new test case: "stops tracking of a job even when an error is raised during job execution"
- The test verifies that
SidekiqStatus.unsetis called even when the job raises an exception - Follows the same test pattern used in
extra_done_log_metadata_spec.rb
Problem Solved
-
Before: If a job raised an exception,
unsetwas never called, leaving orphaned status keys in Redis for 30 minutes -
After: The
ensureblock guarantees cleanup happens regardless of whether the job succeeds or fails - This prevents
SidekiqStatus.running?(job_id)from incorrectly returningtruefor failed jobs
Edited by Victor Prêté