Resque-Stagger
resque-stagger is a simple Ruby gem that allows you to stagger the enqueuing of jobs
in Resque.
Installation
Add this line to your application's Gemfile:
gem 'resque-stagger'
And then execute:
bundle install
Or install it yourself as:
gem install resque-stagger
Usage
require 'resque/staggered'
queue = Resque::Staggered.new(
start_from: Time.now + 60,
number_of_jobs: 10,
unit_time_in_seconds: 300,
queue: 'low'
)
queue.enqueue(MyJobClass, arg1, arg2, arg3)
-
The code sets up a new staggered queue using Resque::Staggered and then enqueues a job with arguments using the
enqueue method of the staggered queue.
-
Based on the options passed to the Resque::Staggered constructor, the staggered queue will enqueue 10 jobs every 5
minutes (300 seconds) starting 60 seconds from the current time, and enqueue the jobs in the "low" queue.
-
So, if this code is run at 12:00 PM, the first set of 10 jobs will be enqueued at 12:01 PM (60 seconds later), the
second set of 10 jobs will be enqueued at 12:06 PM (5 minutes later), the third set of 10 jobs will be enqueued at 12:
11 PM (5 minutes later), and so on.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/parikshit223933/resque-stagger.
License
The gem is available as open source under the terms of
the MIT License.