Coder Social home page Coder Social logo

resque-waiting-room's Introduction

Resque Waiting Room

A Resque plugin. Requires Resque >= 1.19 and a >= 1.9 Ruby (MRI, JRuby or Rubinius).

If you want to limit the number of performs of a job for a given period, extend it with this module.

Installation

Add this line to your application's Gemfile:

gem 'resque-waiting-room'

And then execute:

$ bundle

Or install it yourself as:

$ gem install resque-waiting-room

Usage

Example -- 10 jobs processed every 30 seconds max

require 'resque/plugins/waiting_room'

class UpdateDataFromExternalAPI
  extend Resque::Plugins::WaitingRoom

  # This job can be performed 10 times every 30 seconds
  can_be_performed times: 10, period: 30

  def self.perform(repo_id)
    blah
  end
end

If 10 UpdateDataFromExternalAPI jobs have been performed in 20 seconds, for the next 10 seconds UpdateDataFromExternalAPI jobs will be placed in the waiting_room queue and processed when possible. When the first 30 seconds are elapsed, the counter is set back to 0 and 10 jobs can be performed again. You got to manually tweak the queue names in your workers though.

Testing

We include a matcher

require 'spec/support/matchers'

describe MyJob do
  it 'is rate limited' do
    MyJob.should be_only_performed(times: 100, period: 300)
  end
end

Run tests with the following command

bundle exec rake

Contributing

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

Thanks to the following people for helping out

  • Thomas Devol @socialchorus for adding the RSpec matcher
  • Max Dunn @maxdunn210 for making me switch Resque 2 specific code in it's own branch
  • Jeff Durand @johnnyiller for the update of has_remaining_performs_key using the latest form set and the fix for a rare ttl bug
  • Tatsuya Takamura @ttakamura for raising the issue on the rare ttl bug
  • Omry Zobel @omryYotpo for allowing some customization of the redis key

Build Status Code Climate

resque-waiting-room's People

Contributors

bitdeli-chef avatar johnnyiller avatar julienxx avatar maxdunn210 avatar omryzobel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

resque-waiting-room's Issues

Help testing against edge resque

Hey there!

I'm gearing up to work on Resque 2.0, and I'd like to coordinate better with plugin authors to make sure stuff doesn't break.

I'd like to know a few things:

  1. Can I do something to help get you testing against edge Resque?
  2. Are you monkey-patching anything in Resque currently? Can 2.0 expose an API to help you not have to do that any more?
  3. Do you need any help in bringing your plugin up-to-date with the latest Resque?

Thanks!

Related: https://github.com/defunkt/resque/issues/880

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.