I need to rename a file containing a Sidekiq worker.
worker_a.rb
-> workers/worker_a.rb
The class defined in worker_a.rb
:
class WorkerA
include Sidekiq::Worker
end
I believe this is unsafe because if there's a background job enqueued to run this worker, then when Sidekiq tries to run the enqueued job, it cannot find the class needed.
How should I avoid this error? I've heard about aliasing the old class path to the new one, but I have never done it before.
Thanks!
CodePudding user response:
Same as with database migrations, unsafe things like this can be split in multiple steps.
- Add a new file with the new constant. At this point you are basically copying the code, but that's okay since you are going to delete the old file later anyway
- Edit the code that enqueues the job to use the new constant
Depending on the way your infrastructure is set up you might want to deploy these changes separately, but at this point they're no different from simply introducing a new background job to your codebase.
Once you are sure that there are no jobs refering to the old constants left in the queue, you can safely deploy the last change — remove the old file. It is not used anymore
CodePudding user response:
This is a FAQ in the Sidekiq wiki: https://github.com/mperham/sidekiq/wiki/FAQ#how-do-i-safely-rename-a-worker