We just this week upgraded from Sidekiq Pro to Sidekiq Enterprise and are looking to switch from clockwork for our scheduled jobs to Enterprise's periodic jobs feature. In the wiki page you note:
The
performmethod for periodic workers must take NO parameters (or have default values for all parameters).
Our current clockwork configuration pushes all work into Sidekiq background jobs already, but a bunch of our jobs take arguments even when enqueued periodically. For example, we have a bunch of different notifications (email, push, SMS) that get all triggered the exact same way, and rather than have a different job class for every type, we have a job class that looks like this:
class PostalEventBatchJob < ApplicationJob
def perform(event)
PostalEvents.const_get(event.camelize).enqueue_batch!
end
end
Our clockwork configuration then looks like this:
every(1.hour, "Foo", at: "**:00") do
PostalEventBatchJob.perform_async("foo")
end
every(1.hour, "Bar", at: "**:30") do
PostalEventBatchJob.perform_async("bar")
end
I'm curious what the reason is for not supporting arguments in the periodic job configuration. When I was looking at the sidekiq-ent source code (I won't paste it here) it looks like something that could be reasonably easy to add support for. Something similar to this maybe?
Sidekiq.configure_server do |config|
config.periodic do |mgr|
mgr.register('0 * * * *', PostalEventBatchJob, args: ["foo"])
mgr.register('30 * * * *', PostalEventBatchJob, args: ["bar"])
end
end
I'm not sure if you accept pull requests to sidekiq-ent, but if so I'd be happy to take a stab at adding support for something like this!
Yep, that will work. You can pass in args like that as long as you use String keys:
mgr.register('0 * * * *', PostalEventBatchJob, 'args' => ["foo"])
Oh, even better that it doesn't require any changes! Should the wiki page be updated to note that it's doable?
馃挜 thanks for the quick turn-around @mperham!
Most helpful comment
馃挜 thanks for the quick turn-around @mperham!