0.06
No release in over 3 years
Low commit activity in last 3 years
Resque plugin to add unique jobs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 1.6
~> 0.4
~> 5.8
~> 12.0

Runtime

>= 1.25.0
 Project Readme

ResqueSolo

Gem Version Build Status

ResqueSolo is a resque plugin to add unique jobs to resque.

It is a re-write of resque-loner.

It requires resque 1.25 or greater and works with ruby 2.3 and later.

It removes the dependency on Resque::Helpers, which is deprecated for resque 2.0.

Install

Add the gem to your Gemfile:

gem "resque_solo"

Usage

class UpdateCat
  include Resque::Plugins::UniqueJob
  @queue = :cats

  def self.perform(cat_id)
    # do something
  end
end

If you attempt to queue a unique job multiple times, it is ignored:

Resque.enqueue UpdateCat, 1
=> true
Resque.enqueue UpdateCat, 1
=> nil
Resque.enqueue UpdateCat, 1
=> nil
Resque.size :cats
=> 1
Resque.enqueued? UpdateCat, 1
=> true
Resque.enqueued_in? :dogs, UpdateCat, 1
=> false

Options

lock_after_execution_period

By default, lock_after_execution_period is 0 and enqueued? becomes false as soon as the job is being worked on.

The lock_after_execution_period setting can be used to delay when the unique job key is deleted (i.e. when enqueued? becomes false). For example, if you have a long-running unique job that takes around 10 seconds, and you don't want to requeue another job until you are sure it is done, you could set lock_after_execution_period = 20. Or if you never want to run a long running job more than once per minute, set lock_after_execution_period = 60.

class UpdateCat
  include Resque::Plugins::UniqueJob
  @queue = :cats
  @lock_after_execution_period = 20

  def self.perform(cat_id)
    # do something
  end
end

ttl

By default the created keys have no expiration time, and this gems removes the keys once the job is completed successfully.

If you want to set an expiration time on Redis-level though, you can use the ttl option.

class UpdateCat
  include Resque::Plugins::UniqueJob

  @queue = :cats
  @ttl = 3600 # in seconds

  def self.perform(cat_id)
    # do something
  end
end

Development

Clone this repository, then:

Run tests with resque 1.x locally:

bundle
bundle exec rake test

Test supported versions of resque locally:

appraisal install
appraisal rake test