Pro Expiring Jobs
Clone this wiki locally
Sidekiq Pro supports jobs which expire after a certain length of time.
Jobs that are set to expire can run as long as they want, but an expiring job must start executing before the expiration time.
- Perhaps you want to expire a cache which has a TTL of 30 minutes with a Sidekiq job. If the job doesn't process successfully within 30 minutes, there's no point in continuing to execute the job.
- You use a Sidekiq job to send a daily digest email. If the job doesn't execute within 24 hours, perhaps you want to skip that day as the user might only care about the latest digest.
Require the feature in your initializer:
class SomeWorker include Sidekiq::Worker sidekiq_options expires_in: 1.hour ... end
Dynamically, per job:
expires_in must be a relative time, not an absolute timestamp.
Expiration knows about scheduled jobs: schedule a job to run two hours from now with a one hour expiration and it will expire three hours from now.
If a job expires and was part of a batch, the job result counts as a success and the batch will count as succeeded.