- Notifications
You must be signed in to change notification settings - Fork16
resque plugin to add unique jobs
License
neighborland/resque_solo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ResqueSolo is a resque plugin to add unique jobs to resque.
It is a re-write ofresque-loner.
It requires resque 1.25 or greater and works with ruby 2.3 and later.
It removes the dependency onResque::Helpers
, which is deprecated for resque 2.0.
Add the gem to your Gemfile:
gem"resque_solo"
classUpdateCatincludeResque::Plugins::UniqueJob@queue=:catsdefself.perform(cat_id)# do somethingendend
If you attempt to queue a unique job multiple times, it is ignored:
Resque.enqueue UpdateCat, 1=> trueResque.enqueue UpdateCat, 1=> nilResque.enqueue UpdateCat, 1=> nilResque.size :cats=> 1Resque.enqueued? UpdateCat, 1=> trueResque.enqueued_in? :dogs, UpdateCat, 1=> false
By default, lock_after_execution_period is 0 andenqueued?
becomes false as soon as the jobis being worked on.
Thelock_after_execution_period
setting can be used to delay when the unique job key is deleted(i.e. whenenqueued?
becomesfalse
). For example, if you have a long-running unique job thattakes around 10 seconds, and you don't want to requeue another job until you are sure it is done,you could setlock_after_execution_period = 20
. Or if you never want to run a long runningjob more than once per minute, setlock_after_execution_period = 60
.
classUpdateCatincludeResque::Plugins::UniqueJob@queue=:cats@lock_after_execution_period=20defself.perform(cat_id)# do somethingendend
By default the created keys have no expiration time, and this gems removes thekeys once the job is completed successfully.
If you want to set an expiration time on Redis-level though, you can use thettl
option.
classUpdateCatincludeResque::Plugins::UniqueJob@queue=:cats@ttl=3600# in secondsdefself.perform(cat_id)# do somethingendend
Clone this repository, then:
Run tests with resque 1.x locally:
bundlebundleexec raketest
Test supported versions of resque locally:
appraisal installappraisal raketest
About
resque plugin to add unique jobs