sidekiq-symbols gives you symbol keys for your perform method.
Caveats
I have not tested this in a production environment! The 0.x version is there for a reason!
To use
Add
include Sidekiq::Symbols
to your Sidekiq job class.
class SomeJob
include Sidekiq::Worker
include Sidekiq::Symbols
# ...
end
What it does
Because Sidekiq round-trips job arguments through JSON serialization-deserialization, a hash argument passed to perform_async which uses symbols won't actually be fetchable with symbol keys, because
perform_async(x: 1)
leads to when it gets pulled out of Redis.
perform("x" => 1)
sidekiq-symbols forces perform to use symbols for all its keys, so that this works:
class SomeJob
include Sidekiq::Worker
include Sidekiq::Symbols
def perform(arg, opts = {})
opts[:x] # this works
end
end
SomeJob.perform_async("foo", x: 1)
Note that perform_async("foo", "x" => 1) here would leave opts["x"] == nil since you must use opts[:x].
Keyword arguments
Ruby's keyword arguments are essentially an extension of using a symbol-keyed hash argument, so sidekiq-symbols also enables keyword arguments:
class SomeJob
include Sidekiq::Worker
include Sidekiq::Symbols
def perform(x: 1, y: 2)
# x and y are availalbe
end
end