The goal of this gem is to prioritize resque jobs inside queue. We do this by creating special separated queue (by adding _prioritized
postfix, however it is configurable) for jobs with priority. New queue have ZSet redis type. To pop jobs from this queue we use redis.zpopmax
method.
However, base behaviour of resque queues will not change. Even if you include the plugin. Only new prioritized queus, which was created by enqueue resque workers with priority by Resque.enqueue(TestWorker.with_priority(10), *args)
will have a new behaviour.
- Resque
~> 2.0.0
- Ruby
>= 2.3
Add this line to your application's Gemfile:
gem 'resque-prioritize'
And then execute:
bundle
Or install it yourself as:
gem install resque-prioritize
You can change default prioritized queue postfix by
Resque::Plugins::Prioritize.prioritized_queue_postfix = '_custom_postfix'
By default it is equal _prioritized
class TestWorker
include Resque::Plugins::Prioritize
def self.perform(*args)
end
end
All workers and their descendants, which include this plugin, will already have a prioritize system.
You can use it
Resque.enqueue(TestWorker.with_priority(10), *args)
If, for some reason, you need to remove priority from the class, you could use without_priority
method:
TestWorker.with_priority(10).without_priority # -> TestWorker
If you will call without_priority
for entry class, it will returns that class:
TestWorker.without_priority # -> TestWorker
You should to run resque workers:
QUEUE=* COUNT=1 bundle exec rake resque:workers
And after it:
bundle exec rake spec
- Fork it
- 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 new Pull Request
Bug reports and pull requests are welcome on GitHub at https://github.com/verbit/resque-prioritize. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.