Scheduled Jobs - rselk/sidekiq GitHub Wiki
Sidekiq allows you to schedule the time when a job will be executed. You use perform_in(interval, *args)
or perform_at(timestamp, *args)
rather than the standard perform_async(*args)
:
MyWorker.perform_in(3.hours, 'mike', 1)
MyWorker.perform_at(3.hours.from_now, 'mike', 1)
This is useful for example if you want to send the user an email 3 hours after they sign up.
Recurring Jobs
For recurring tasks, I recommend using the clockwork, whenever, sidekiq-cron or sidetiq gems.
With whenever, you'll just do something like this in config/schedule.rb
:
every 1.day, :at => '12:01 pm' do
runner 'Warehouse::FtpPull.perform_async'
end
Checking for New Jobs
Sidekiq checks for scheduled jobs every 15 seconds by default. You can adjust this interval:
Sidekiq.configure_server do |config|
config.poll_interval = 15
end
WARNING: If you have dozens or hundreds of Sidekiq processes, you should raise the poll_interval significantly. process_count * 5
is a reasonable poll_interval for most. Otherwise your processes will slam Redis constantly looking for new scheduled jobs to run.