resque-population-control 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/resque/plugins/population_control.rb +7 -4
- metadata +1 -2
- data/lib/resque/population/control.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c479293957e554a99b6d9eaee204547149bc2bc
|
4
|
+
data.tar.gz: ea106605ddf5dcb92f4707c073016c0ca18b41cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0d7928de244a58296757f893a32da9a3c9ce4865c373113abca921b36cc8c97813910a6c0d891764a7103f391433d92703f42c77ac40fe2c8b041269bf9b0b
|
7
|
+
data.tar.gz: 88624ec32e93f3b3bfc74c47020e2a5605fd9caa6c3ff497d5197c28f29c4b26bbfce12961d8846a008e0322aa8f0e58686e816a327cf6a27c17a7e73fe1f049
|
data/README.md
CHANGED
@@ -35,6 +35,25 @@ The following examples limits Job to having at most 100 enqeueud or running inst
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
By default, a Resque::Plugins::PopulationControl::PopulationExceeded exception will be thrown whenever things get out of hand.
|
39
|
+
If you wish to suppress this, there is an option to do that. This will cause things to fail silently and prevent any job from getting enqueued if the current population is past the limit.
|
40
|
+
To get more info and visibility in these situations, you can implement on_population_exceeded to add things like logging and whatever else you deem needed.
|
41
|
+
|
42
|
+
class Job
|
43
|
+
extend Resque::Plugins::PopulationControl
|
44
|
+
population_control 100, :suppress_exceptions => true
|
45
|
+
|
46
|
+
@queue = :jobs
|
47
|
+
|
48
|
+
def self.perform(customer_id)
|
49
|
+
...
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.on_population_exceeded max_size, *args
|
53
|
+
logger.debug "Attempt to enqueue #{name} with payload #{args.inspect} failed since population exceeds #{max_size}."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
## Development
|
39
58
|
|
40
59
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Resque
|
2
2
|
module Plugins
|
3
3
|
module PopulationControl
|
4
|
-
VERSION = "0.
|
4
|
+
VERSION = "0.4.0"
|
5
5
|
|
6
6
|
class PopulationExceeded < ::StandardError; end;
|
7
7
|
|
8
|
-
def population_control max
|
8
|
+
def population_control max, options = {}
|
9
9
|
@population_control_max = max
|
10
|
+
@population_control_options = options
|
10
11
|
end
|
11
12
|
|
12
13
|
def population_controlled?
|
@@ -17,8 +18,10 @@ module Resque
|
|
17
18
|
population_control_count = population_control_increment
|
18
19
|
if population_control_count > population_control_max
|
19
20
|
population_control_decrement
|
20
|
-
|
21
|
-
|
21
|
+
if respond_to? :on_population_exceeded
|
22
|
+
on_population_exceeded(population_control_max, *args)
|
23
|
+
end
|
24
|
+
unless @population_control_options[:suppress_exceptions]
|
22
25
|
raise PopulationExceeded, "Enqueuing #{name} would exceed max allowed population of #{population_control_max}."
|
23
26
|
end
|
24
27
|
false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-population-control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Misha Conway
|
@@ -69,7 +69,6 @@ files:
|
|
69
69
|
- bin/setup
|
70
70
|
- lib/resque-population-control.rb
|
71
71
|
- lib/resque/plugins/population_control.rb
|
72
|
-
- lib/resque/population/control.rb
|
73
72
|
- population-control.gemspec
|
74
73
|
homepage: https://github.com/MishaConway/resque-population-control
|
75
74
|
licenses: []
|
@@ -1 +0,0 @@
|
|
1
|
-
require '../plugins/population_control'
|