Add a Round-Robin based process to your flow.
Add this line to your application's Gemfile:
gem 'roundrobin'
And then execute:
$ bundle
Or install it yourself as:
$ gem install roundrobin
Initialize your Round-Robin instance
>> rr = Roundrobin.new
or
>> rr = Roundrobin.new("redis://:[email protected]:6380/15")
Now you can ask for the next item (in a Round-Robin logic)
>> rr.next(%w(foo bar))
=> "foo"
>> rr.next(%w(foo bar))
=> "bar"
>> rr.next(%w(foo bar))
=> "foo"
>> candidates = [{name: 'John', email: '[email protected]'}, {name: 'Sara', email: '[email protected]'}])
>> rr.next(candidates)
=> {name: 'John', email: '[email protected]'}
>> rr.next(candidates)
=> {name: 'Sara', email: '[email protected]'}
>> rr.next(candidates)
=> {name: 'John', email: '[email protected]'}
All the data will be persisted to your DB, so you can restart your server, or do this in multiple threads and the results will be the same: you will be using the Round Robin algorith.
$ cd roundrobin
$ gem build roundrobin.gemspec
$ gem install ./roundrobin-XXX.gem
- Fork it ( https://github.com/archdaily/roundrobin/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request