No commit activity in last 3 years
No release in over 3 years
Sliding Window unique-job workflow for Resque jobs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

ResqueSlidingWindow

Gem Version

Want a sliding window for debouncing bursty Resque events? Here it is.

Installation

Add this line to your application's Gemfile:

gem 'resque_sliding_window'
gem 'resque-scheduler', require: 'resque_scheduler', git: "https://github.com/jonhyman/resque-scheduler.git" # prefered repo

And then execute:

$ bundle

Setup

You might have a glance at the resque-scheduler gem. You need to setup a worker. To run one manually, simply:

rake resque:scheduler

But again, see the resque-scheduler gem as there is some setup for the rake task.

Usage

module Jobs
  class Publish
    extend Resque::Plugins::SlidingWindow

    @queue = :low

    def self.perform(id)
      # Crazy stuff
    end
  end
end

Resque.enqueue_in(30, Jobs::Publish, id)

This will put a job in a delayed queue for 30 seconds. If a similar job is entered (same args, same klass), it will be deleted in favor of the new 30-second job. However, it can only be pushed off for a 1m 30s from its initial queue-time before it force runs one. When it forces one through, others will not be run.

Default max_time is 1m and 30s. To change this:

module Jobs
  class Publish
    extend Resque::Plugins::SlidingWindow

    @queue = :low

    def self.max_time
      30.minutes
    end

    def self.perform(id)
      # Crazy stuff
    end
  end
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request