Skip to content

A resque plugin for limiting how many of a specific job can run concurrently

License

Notifications You must be signed in to change notification settings

wr0ngway/resque-concurrent-restriction

Repository files navigation

resque-concurrent-restriction

Resque Concurrent Restriction is a plugin for the Resque queueing system. It allows one to specify how many of the given job can run concurrently.

Resque Concurrent Restriction requires Resque 1.25 and redis 2.2

Build Status

Install

Install it from the command-line:

gem install resque-concurrent-restriction

or add it to your Gemfile:

gem 'resque-concurrent-restriction', '~> 0.6'

To use

It is especially useful when a system has intensive jobs for which you should only run a few at a time. What you should do for the IntensiveJob is to make it extend Resque::Plugins::ConcurrentRestriction and specify the concurrent limit (defaults to 1). For example:

class IntensiveJob
  extend Resque::Plugins::ConcurrentRestriction
  concurrent 4

  def perform
    # ...
  end
end

That means the IntensiveJob can not have more than 4 jobs running simultaneously.

One can also make the concurrency limit depend on the parameters of a job. For example, if you always pass a user_id as the first parameter, you can restrict the job to run N concurrent jobs per user:

class IntensiveJob
  extend Resque::Plugins::ConcurrentRestriction
  concurrent 4

  def self.concurrent_identifier(*args)
    args.first.to_s
  end

  def perform
    # ...
  end
end

Author

Code was originally forked from the resque-restriction plugin (Richard Huang :: [email protected] :: @flyerhzm), but diverged enough that it warranted being its own plugin to keep the code simple.

Matt Conway :: [email protected] :: @mattconway

Copyright

Copyright (c) 2011 Matt Conway. See LICENSE for details.

About

A resque plugin for limiting how many of a specific job can run concurrently

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages