-
-
Notifications
You must be signed in to change notification settings - Fork 280
From Sidekiq to Shoryuken
Nikita Bulai edited this page Sep 8, 2022
·
29 revisions
Shoryuken is a drop-in replacement for Sidekiq, the code changes should be minor s/sidekiq/shoryuken
. But as Shoryuken "reads" messages from SQS, instead of Redis, you will probably need a three steps migration:
- Stop sending jobs to Sidekiq
- Start using Shoryuken
- Keep Sidekiq running until it consumes all pending jobs.
class MyWorker
include Sidekiq::Worker
sidekiq_options queue: 'my_queue'
def perform(arg)
# ...
end
end
class MyWorker
include Shoryuken::Worker
shoryuken_options queue: 'my_queue', auto_delete: true
def perform(sqs_msg, arg)
# ...
end
end
Note that if your Sidekiq worker has more than 1 argument you will need to configure message body parser for Shoryuken worker and define only one argument in a #perform
method:
class YourWorker
include Shoryuken::Worker
shoryuken_options queue: "queue", auto_delete: true, body_parser: JSON
def perform(_sqs_message, args)
args.fetch("user_id")
args.fetch("post_id")
# ...
end
end
YourWorker.perform_async(user_id: "XXX", post_id: "YYY")
concurrency: 25
pidfile: tmp/pids/sidekiq.pid
queues:
- default
- [myqueue, 2]
concurrency: 25
pidfile: tmp/pids/shoryuken.pid
queues:
- default
- [myqueue, 2]
MyWorker.perform_async('test')
MyWorker.perform_async('test')
bundle exec sidekiq -r ./my_worker.rb -q my_queue
bundle exec shoryuken -r ./my_worker.rb -q my_queue