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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 393c9c0078543f7c093ea7b6a918212db58f2606
4
- data.tar.gz: 124adb43a962a87db494620c432a1da3afb33e84
3
+ metadata.gz: 4c479293957e554a99b6d9eaee204547149bc2bc
4
+ data.tar.gz: ea106605ddf5dcb92f4707c073016c0ca18b41cf
5
5
  SHA512:
6
- metadata.gz: 58b09927f36d92500573ca6ba36053bc1bc4c11eedb52152d325b80ca53e5f84c0a2c450d414a195493bc950dfc308401504c00093479d20b79f4eef2bc33bc1
7
- data.tar.gz: f522188248425c90f140fdecd4d5e9f2ec5f0c538e618f0412544c751c282d52c422e55e7b9a4c66e0b511d020f76451c996a1e7c8eae964f0ab02d4b5581303
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.3.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
- suppress_exception = respond_to?(:on_population_exceeded) && on_population_exceeded(population_control_max, *args)
21
- unless suppress_exception
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.3.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'