A simple algorithm for 4 shards. Work will be distributed to 4 queue shards (25% chance) from their name calling String#sum
.
# Make a module
module SidekiqWorkersOptions
class Within24HoursQueue
SHARDS = ENV.fetch("SIDEKIQ_SHARDS", 4)
def self.included(module)
shard_number = module.name.sum % SHARDS
queue = "within_24_hours_#{shard_number}".to_sym
module.sidekiq_options(queue: queue)
end
end
end
# Usage:
class UserDataExportWorker
include Sidekiq::Job
include SidekiqWorkersOptions::Within24HoursQueue
end
For more strategies, check FaQueue.