|
1 | | -resque-concurrent-restriction |
2 | | -=============== |
| 1 | +# resque-concurrent-restriction |
3 | 2 |
|
4 | | -Resque Concurrent Restriction is a plugin for the [Resque][0] queueing system (http://github.com/defunkt/resque). It allows one to specify how many of the given job can run concurrently. |
| 3 | +Resque Concurrent Restriction is a plugin for the [Resque][0] queueing system. It allows one to specify how many of the given job can run concurrently. |
5 | 4 |
|
6 | 5 | Resque Concurrent Restriction requires Resque 1.25 and redis 2.2 |
7 | 6 |
|
8 | | -[](http://travis-ci.org/wr0ngway/resque-concurrent-restriction) |
| 7 | +[](http://travis-ci.org/russCloak/resque-concurrent-restriction) |
9 | 8 |
|
10 | | -Install |
11 | | -------- |
| 9 | +## Install |
12 | 10 |
|
13 | | - sudo gem install resque-concurrent-restriction |
| 11 | +Install it from the command-line: |
14 | 12 |
|
15 | | -To use |
16 | | ------- |
| 13 | +```bash |
| 14 | +gem install resque-concurrent-restriction |
| 15 | +``` |
17 | 16 |
|
18 | | -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: |
| 17 | +or add it to your `Gemfile`: |
19 | 18 |
|
20 | | - class IntensiveJob |
21 | | - extend Resque::Plugins::ConcurrentRestriction |
22 | | - concurrent 4 |
23 | | - |
24 | | - #rest of your class here |
25 | | - end |
| 19 | +```ruby |
| 20 | +gem 'resque-concurrent-restriction', '~> 0.6' |
| 21 | +``` |
26 | 22 |
|
27 | | -That means the IntensiveJob can not have more than 4 jobs running simultaneously |
| 23 | +## To use |
28 | 24 |
|
29 | | -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 param, you can restrict the job to run N concurrent jobs per user: |
| 25 | +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: |
30 | 26 |
|
31 | | - class IntensiveJob |
32 | | - extend Resque::Plugins::ConcurrentRestriction |
33 | | - concurrent 4 |
| 27 | +```ruby |
| 28 | +class IntensiveJob |
| 29 | + extend Resque::Plugins::ConcurrentRestriction |
| 30 | + concurrent 4 |
34 | 31 |
|
35 | | - def self.concurrent_identifier(*args) |
36 | | - args.first.to_s |
37 | | - end |
38 | | - |
39 | | - #rest of your class here |
40 | | - end |
| 32 | + def perform |
| 33 | + # ... |
| 34 | + end |
| 35 | +end |
| 36 | +``` |
| 37 | + |
| 38 | +That means the IntensiveJob can not have more than 4 jobs running simultaneously. |
| 39 | + |
| 40 | +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: |
| 41 | + |
| 42 | +```ruby |
| 43 | +class IntensiveJob |
| 44 | + extend Resque::Plugins::ConcurrentRestriction |
| 45 | + concurrent 4 |
| 46 | + |
| 47 | + def self.concurrent_identifier(*args) |
| 48 | + args.first.to_s |
| 49 | + end |
| 50 | + |
| 51 | + def perform |
| 52 | + # ... |
| 53 | + end |
| 54 | +end |
| 55 | +``` |
| 56 | + |
| 57 | +## Author |
41 | 58 |
|
42 | | -Author |
43 | | ------- |
44 | 59 | Code was originally forked from the [resque-restriction][1] plugin (Richard Huang :: flyerhzm@gmail.com :: @flyerhzm), but diverged enough that it warranted being its own plugin to keep the code simple. |
45 | 60 |
|
46 | 61 | Matt Conway :: matt@conwaysplace.com :: @mattconway |
47 | 62 |
|
48 | | -Copyright |
49 | | ---------- |
| 63 | +## Copyright |
| 64 | + |
50 | 65 | Copyright (c) 2011 Matt Conway. See LICENSE for details. |
51 | 66 |
|
52 | 67 | [0]: http://github.com/defunkt/resque |
|
0 commit comments