resque-waiting-room 0.1.3 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9058938da957ee322a1422f2564ada3b40c9b8cd
4
+ data.tar.gz: c12c80cb78497fe63b84adb9c4763a693d12299c
5
+ SHA512:
6
+ metadata.gz: f0bb708ab5a6dc14381f3d77aa9c0023cd86d3485212fb6df8fa01fb02e896ee2b919b40cd03e4cec9a6e01b3c3715045a7eb79584db0a7e000dd7db2a33de92
7
+ data.tar.gz: 373883a28538dfc7141000109bb3fb9453cce8907aafac166ccd723b095d84390620d5b2bc7cb5209558c9ba87b9f443356bfcdbd5e7289f05f7e4982826b2f8
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ tags
6
+ .idea
data/.rspec CHANGED
@@ -1,3 +1 @@
1
1
  --colour
2
- --format Fuubar
3
- --drb
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx-19mode
data/Gemfile CHANGED
@@ -1,4 +1,13 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in resque-waiting-room.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'resque', '~>1.24.1'
8
+ end
9
+
10
+ group :test do
11
+ gem 'rspec'
12
+ gem 'mock_redis'
13
+ end
data/README.markdown CHANGED
@@ -1,12 +1,28 @@
1
1
  Resque Waiting Room
2
2
  ===================
3
3
 
4
- A [Resque][rq] plugin. Requires Resque 1.19.0.
4
+ A [Resque][rq] plugin. Requires Resque >= 1.19 and a >= 1.9 Ruby (MRI, JRuby or Rubinius).
5
5
 
6
6
  If you want to limit the number of performs of a job for a given period, extend it
7
7
  with this module.
8
8
 
9
- For example:
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'resque-waiting-room'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install resque-waiting-room
22
+
23
+ ## Usage
24
+
25
+ #### Example -- 10 jobs processed every 30 seconds max
10
26
 
11
27
  require 'resque/plugins/waiting_room'
12
28
 
@@ -21,8 +37,39 @@ For example:
21
37
  end
22
38
  end
23
39
 
24
- If 10 UpdateDataFromExternalAPI jobs have been performed in less than
25
- 30 seconds, next job will be placed placed in the waiting_room queue
26
- and processed when possible.
40
+ If 10 UpdateDataFromExternalAPI jobs have been performed in 20
41
+ seconds, for the next 10 seconds UpdateDataFromExternalAPI jobs
42
+ will be placed in the waiting_room queue and processed when possible.
43
+ When the first 30 seconds are elapsed, the counter is set back to 0
44
+ and 10 jobs can be performed again.
45
+ You got to manually tweak the queue names in your workers though.
46
+
47
+ ## Testing
48
+
49
+ We include a matcher
50
+
51
+ require 'spec/support/matchers'
52
+
53
+ describe MyJob do
54
+ it 'is rate limited' do
55
+ MyJob.should be_only_performed(times: 100, period: 300)
56
+ end
57
+ end
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
66
+
67
+ ## Thanks to the following people for helping out ##
68
+
69
+ - Thomas Devol [@socialchorus](https://github.com/socialchorus) for adding the RSpec matcher
70
+ - Max Dunn [@maxdunn210](https://github.com/maxdunn210) for making me switch Resque 2 specific code in it's own branch
71
+ - Jeff Durand [@johnnyiller](https://github.com/johnnyiller) for the update of has_remaining_performs_key using the latest form set
72
+
73
+ [rq]: http://github.com/resque/resque
27
74
 
28
- [rq]: http://github.com/julienXX/resque
75
+ [![Build Status](https://travis-ci.org/julienXX/resque-waiting-room.png)](https://travis-ci.org/julienXX/resque-waiting-room) [![Code Climate](https://codeclimate.com/github/julienXX/resque-waiting-room.png)](https://codeclimate.com/github/julienXX/resque-waiting-room)
@@ -1,13 +1,13 @@
1
1
  module Resque
2
2
  class Job
3
- class <<self
3
+ class << self
4
4
  alias_method :origin_reserve, :reserve
5
5
 
6
6
  def reserve(queue)
7
7
  if queue =~ /^waiting_room/ && Resque.size(queue) > 0
8
8
  payload = Resque.pop(queue)
9
9
  if payload
10
- klass = constantize(payload['class'])
10
+ klass = Kernel.const_get(payload['class'])
11
11
  repushed_in_waiting_room = klass.repush(*payload['args'])
12
12
 
13
13
  return new(queue, payload) unless repushed_in_waiting_room
@@ -17,7 +17,6 @@ module Resque
17
17
  origin_reserve(queue)
18
18
  end
19
19
  end
20
-
21
20
  end
22
21
  end
23
22
  end
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module WaitingRoom
4
- VERSION="0.1.3"
4
+ VERSION = '0.2.2'
5
5
  end
6
6
  end
7
7
  end
@@ -11,27 +11,24 @@ module Resque
11
11
  end
12
12
 
13
13
  def waiting_room_redis_key
14
- [self.to_s, "remaining_performs"].compact.join(":")
14
+ [self.to_s, 'remaining_performs'].compact.join(':')
15
15
  end
16
16
 
17
17
  def before_perform_waiting_room(*args)
18
18
  key = waiting_room_redis_key
19
+ return unless remaining_performs_key?(key)
19
20
 
20
- if has_remaining_performs_key?(key)
21
- performs_left = Resque.redis.decrby(key, 1).to_i
22
-
23
- if performs_left < 1
24
- Resque.push 'waiting_room', :class => self.to_s, :args => args
25
- raise Resque::Job::DontPerform
26
- end
21
+ performs_left = Resque.redis.decrby(key, 1).to_i
22
+ if performs_left < 1
23
+ Resque.push 'waiting_room', class: self.to_s, args: args
24
+ raise Resque::Job::DontPerform
27
25
  end
28
26
  end
29
27
 
30
- def has_remaining_performs_key?(key)
31
- # Redis SETNX: sets the keys if it doesn't exist, returns true if key was created
32
- new_key = Resque.redis.setnx(key, @max_performs - 1)
33
- Resque.redis.expire(key, @period) if new_key
34
-
28
+ def remaining_performs_key?(key)
29
+ # Redis SET: with the ex and nx option sets the keys if it doesn't exist,
30
+ # returns true if key was created redis => 2.6 required
31
+ new_key = Resque.redis.set(key, @max_performs - 1, ex: @period, nx: true)
35
32
  return !new_key
36
33
  end
37
34
 
@@ -46,4 +43,3 @@ module Resque
46
43
  end
47
44
  end
48
45
  end
49
-
@@ -19,13 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.files += Dir.glob("lib/**/*")
20
20
  s.files += Dir.glob("spec/**/*")
21
21
 
22
- s.add_development_dependency 'rake', '~>0.9.2.2'
23
- s.add_development_dependency 'resque', '~>1.19.0'
24
- s.add_development_dependency 'rspec', '~>2.8.0'
25
- s.add_development_dependency 'fuubar', '~>1.0.0'
26
- s.add_development_dependency 'spork', '~>0.9.0'
27
- s.add_development_dependency 'guard', '~>0.10.0'
28
- s.add_development_dependency 'guard-rspec', '~>0.6.0'
29
- s.add_development_dependency 'guard-spork', '~>0.3.0'
30
- s.add_development_dependency 'rb-fsevent', '~>0.4.3.1'
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'resque'
31
24
  end
@@ -1,41 +1,45 @@
1
1
  require File.join(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  describe Resque::Job do
4
+
4
5
  before(:each) do
5
6
  Resque.redis.flushall
6
7
  end
7
8
 
8
- context "normal job" do
9
- it "should trigger original reserve" do
10
- Resque.push('normal', :class => 'DummyJob', :args => ['any args'])
11
- Resque::Job.reserve('normal').should == Resque::Job.new('normal', {'class' => 'DummyJob', 'args' => ['any args']})
12
- Resque::Job.reserve('waiting_room').should be_nil
9
+ context 'normal job' do
10
+ it 'should trigger original reserve' do
11
+ Resque.push('normal', class: 'DummyJob', args: ['any args'])
12
+ expect(Resque::Job.reserve('normal'))
13
+ .to eq(Resque::Job.new('normal', 'class' => 'DummyJob', 'args' => ['any args']))
14
+ expect(Resque::Job.reserve('waiting_room')).to eq(nil)
13
15
  end
14
16
  end
15
17
 
16
- context "waiting_room job" do
17
- it "should push in the waiting_room queue when reserve from waiting_room queue" do
18
- Resque.push('waiting_room', :class => 'DummyJob', :args => ['any args'])
19
- Resque::Job.reserve('waiting_room').should == Resque::Job.new('waiting_room', {'class' => 'DummyJob', 'args' => ['any args']})
20
- Resque::Job.reserve('normal').should be_nil
18
+ context 'waiting_room job' do
19
+ it 'should push in the waiting_room queue when reserve from waiting_room queue' do
20
+ Resque.push('waiting_room', class: 'DummyJob', args: ['any args'])
21
+ expect(Resque::Job.reserve('waiting_room'))
22
+ .to eq(Resque::Job.new('waiting_room', 'class' => 'DummyJob', 'args' => ['any args']))
23
+ expect(Resque::Job.reserve('normal')).to eq(nil)
21
24
  end
22
25
 
23
- it "should push back to waiting_room queue when still restricted" do
24
- Resque.push('waiting_room', :class => 'DummyJob', :args => ['any args'])
25
- DummyJob.should_receive(:repush).with('any args')
26
- Resque::Job.reserve('waiting_room').should == Resque::Job.new('waiting_room', {'class' => 'DummyJob', 'args' => ['any args']})
27
- Resque::Job.reserve('waiting_room').should be_nil
28
- Resque::Job.reserve('normal').should be_nil
26
+ it 'should push back to waiting_room queue when still restricted' do
27
+ Resque.push('waiting_room', class: 'DummyJob', args: ['any args'])
28
+ expect(DummyJob).to receive(:repush).with('any args')
29
+ expect(Resque::Job.reserve('waiting_room'))
30
+ .to eq(Resque::Job.new('waiting_room', 'class' => 'DummyJob', 'args' => ['any args']))
31
+ expect(Resque::Job.reserve('waiting_room')).to eq(nil)
32
+ expect(Resque::Job.reserve('normal')).to eq(nil)
29
33
  end
30
34
 
31
- it "should not repush when reserve normal queue" do
32
- Resque.push('normal', :class => 'DummyJob', :args => ['any args'])
33
- DummyJob.should_not_receive(:repush).with('any args')
34
- Resque::Job.reserve('normal').should == Resque::Job.new('normal', {'class' => 'DummyJob', 'args' => ['any args']})
35
- Resque::Job.reserve('normal').should be_nil
36
- Resque::Job.reserve('waiting_room').should be_nil
35
+ it 'should not repush when reserve normal queue' do
36
+ Resque.push('normal', class: 'DummyJob', args: ['any args'])
37
+ expect(DummyJob).not_to receive(:repush).with('any args')
38
+ expect(Resque::Job.reserve('normal'))
39
+ .to eq(Resque::Job.new('normal', 'class' => 'DummyJob', 'args' => ['any args']))
40
+ expect(Resque::Job.reserve('normal')).to eq(nil)
41
+ expect(Resque::Job.reserve('waiting_room')).to eq(nil)
37
42
  end
38
43
  end
39
44
 
40
45
  end
41
-
@@ -5,114 +5,147 @@ describe Resque::Plugins::WaitingRoom do
5
5
  Resque.redis.flushall
6
6
  end
7
7
 
8
- it "should validate the Resque linter" do
8
+ it 'should validate the Resque linter' do
9
9
  Resque::Plugin.lint(Resque::Plugins::WaitingRoom)
10
10
  end
11
11
 
12
- context "can_be_performed" do
13
- it "should raise InvalidParams" do
14
- expect {DummyJob.can_be_performed('lol')}.should raise_error(Resque::Plugins::WaitingRoom::MissingParams)
12
+ context 'can_be_performed' do
13
+ it 'should raise InvalidParams' do
14
+ expect { DummyJob.can_be_performed('lol') }
15
+ .to raise_error(Resque::Plugins::WaitingRoom::MissingParams)
15
16
  end
16
17
 
17
- it "should assign @period and @max_performs" do
18
- DummyJob.instance_variable_get("@period").should == 30
19
- DummyJob.instance_variable_get("@max_performs").should == 10
18
+ it 'should assign @period and @max_performs' do
19
+ expect(DummyJob.instance_variable_get('@period')).to eq(30)
20
+ expect(DummyJob.instance_variable_get('@max_performs')).to eq(10)
20
21
  end
21
22
  end
22
23
 
23
- context "waiting_room_redis_key" do
24
- it "should generate a redis key name based on the class" do
25
- DummyJob.waiting_room_redis_key.should == 'DummyJob:remaining_performs'
24
+ context 'waiting_room_redis_key' do
25
+ it 'should generate a redis key name based on the class' do
26
+ expect(DummyJob.waiting_room_redis_key)
27
+ .to eq('DummyJob:remaining_performs')
26
28
  end
27
29
  end
28
30
 
29
- context "before_perform_waiting_room" do
30
- it "should call waiting_room_redis_key" do
31
- DummyJob.should_receive(:waiting_room_redis_key).and_return('DummyJob:remaining_performs')
31
+ context 'custom matcher' do
32
+ it 'should match positive' do
33
+ expect(DummyJob).to be_only_performed(times: 10, period: 30)
34
+ end
35
+ end
36
+
37
+ context 'before_perform_waiting_room' do
38
+ it 'should call waiting_room_redis_key' do
39
+ expect(DummyJob).to receive(:waiting_room_redis_key)
40
+ .and_return('DummyJob:remaining_performs')
32
41
  DummyJob.before_perform_waiting_room('args')
33
42
  end
34
43
 
35
- it "should call has_remaining_performs_key?" do
36
- DummyJob.should_receive(:has_remaining_performs_key?).and_return(false)
44
+ it 'should call remaining_performs_key?' do
45
+ expect(DummyJob).to receive(:remaining_performs_key?).and_return(false)
37
46
  DummyJob.before_perform_waiting_room('args')
38
47
  end
39
48
 
40
- it "should decrement performs" do
49
+ it 'should decrement performs' do
41
50
  DummyJob.before_perform_waiting_room('args')
42
- Resque.redis.get("DummyJob:remaining_performs").should =="9"
51
+ expect(Resque.redis.get('DummyJob:remaining_performs')).to eq('9')
43
52
  DummyJob.before_perform_waiting_room('args')
44
- Resque.redis.get("DummyJob:remaining_performs").should =="8"
53
+ expect(Resque.redis.get('DummyJob:remaining_performs')).to eq('8')
45
54
  DummyJob.before_perform_waiting_room('args')
46
- Resque.redis.get("DummyJob:remaining_performs").should =="7"
55
+ expect(Resque.redis.get('DummyJob:remaining_performs')).to eq('7')
47
56
  end
48
57
 
49
- it "should prevent perform once there are no performs left" do
50
- 9.times {DummyJob.before_perform_waiting_room('args')}
51
- Resque.redis.get("DummyJob:remaining_performs").should =="1"
52
- expect { DummyJob.before_perform_waiting_room('args') }.should raise_exception(Resque::Job::DontPerform)
58
+ it 'should prevent perform once there are no performs left' do
59
+ 9.times { DummyJob.before_perform_waiting_room('args') }
60
+ expect(Resque.redis.get('DummyJob:remaining_performs')).to eq('1')
61
+ expect { DummyJob.before_perform_waiting_room('args') }
62
+ .to raise_exception(Resque::Job::DontPerform)
53
63
  end
54
64
  end
55
65
 
56
- context "has_remaining_performs_key?" do
57
- it "should set a redis key" do
58
- Resque.redis.should_receive(:setnx)
59
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
66
+ context 'remaining_performs_key?' do
67
+ before do
68
+ @key = DummyJob.waiting_room_redis_key
69
+ @max = DummyJob.instance_variable_get('@max_performs') - 1
70
+ @period = DummyJob.instance_variable_get('@period')
60
71
  end
61
72
 
62
- it "should expire the redis key" do
63
- Resque.redis.should_receive(:setnx).and_return(true)
64
- Resque.redis.should_receive(:expire)
65
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
73
+ it 'should set a redis key' do
74
+ expect(Resque.redis).to receive(:set)
75
+ .with(@key, @max, ex: @period, nx: true)
76
+ DummyJob.remaining_performs_key?(DummyJob.waiting_room_redis_key)
66
77
  end
67
78
 
68
- it "should not re-expire the redis key if it is already created" do
69
- Resque.redis.should_receive(:setnx).and_return(true)
70
- Resque.redis.should_receive(:expire)
71
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
72
- Resque.redis.should_receive(:setnx).and_return(false)
73
- Resque.redis.should_not_receive(:expire)
74
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
79
+ it 'should expire the redis key' do
80
+ expect(Resque.redis).to receive(:set)
81
+ .with(@key, @max, ex: @period, nx: true)
82
+ .and_return(true)
83
+ DummyJob.remaining_performs_key?(DummyJob.waiting_room_redis_key)
75
84
  end
76
85
 
77
- it "should return false if the key is new" do
78
- Resque.redis.should_receive(:setnx).and_return(true)
79
- Resque.redis.should_receive(:expire)
80
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key).should == false
86
+ it 'should not re-expire the redis key if it is already created' do
87
+ expect(Resque.redis).to receive(:set)
88
+ .with(@key, @max, ex: @period, nx: true)
89
+ .and_return(true)
90
+ DummyJob.remaining_performs_key?(DummyJob.waiting_room_redis_key)
91
+ expect(Resque.redis).to receive(:set)
92
+ .with(@key, @max, ex: @period, nx: true)
93
+ .and_return(false)
94
+ DummyJob.remaining_performs_key?(DummyJob.waiting_room_redis_key)
81
95
  end
82
96
 
83
- it "should return true if the key was already created" do
84
- Resque.redis.should_receive(:setnx).and_return(false)
85
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key).should == true
97
+ it 'should return false if the key is new' do
98
+ expect(Resque.redis).to receive(:set)
99
+ .with(@key, @max, ex: @period, nx: true)
100
+ .and_return(true)
101
+ expect(DummyJob.remaining_performs_key?(DummyJob.waiting_room_redis_key))
102
+ .to eq(false)
103
+ end
104
+
105
+ it 'should return true if the key was already created' do
106
+ expect(Resque.redis).to receive(:set)
107
+ .with(@key, @max, ex: @period, nx: true)
108
+ .and_return(false)
109
+ expect(DummyJob.remaining_performs_key?(DummyJob.waiting_room_redis_key))
110
+ .to eq(true)
86
111
  end
87
112
  end
88
113
 
89
- context "repush" do
90
- it "should call waiting_room_redis_key" do
91
- DummyJob.should_receive(:waiting_room_redis_key).and_return('DummyJob:remaining_performs')
114
+ context 'repush' do
115
+ it 'should call waiting_room_redis_key' do
116
+ expect(DummyJob).to receive(:waiting_room_redis_key)
117
+ .and_return('DummyJob:remaining_performs')
92
118
  DummyJob.repush('args')
93
119
  end
94
120
 
95
- it "should get the key" do
96
- Resque.redis.should_receive(:get).with(DummyJob.waiting_room_redis_key)
121
+ it 'should get the key' do
122
+ expect(Resque.redis).to receive(:get)
123
+ .with(DummyJob.waiting_room_redis_key)
97
124
  DummyJob.repush('args')
98
125
  end
99
126
 
100
- it "should push in the waiting_room if there are no performs left" do
101
- Resque.redis.should_receive(:get).with(DummyJob.waiting_room_redis_key).and_return('0')
102
- Resque.should_receive(:push).with('waiting_room', class: 'DummyJob', args: ['args']).and_return(true)
127
+ it 'should push in the waiting_room if there are no performs left' do
128
+ expect(Resque.redis).to receive(:get)
129
+ .with(DummyJob.waiting_room_redis_key)
130
+ .and_return('0')
131
+ expect(Resque).to receive(:push)
132
+ .with('waiting_room', class: 'DummyJob', args: ['args'])
133
+ .and_return(true)
103
134
  DummyJob.repush('args')
104
135
  end
105
136
 
106
- it "should return true if there were no performs left" do
107
- Resque.redis.should_receive(:get).with(DummyJob.waiting_room_redis_key).and_return('0')
108
- DummyJob.repush('args').should == true
137
+ it 'should return true if there were no performs left' do
138
+ expect(Resque.redis).to receive(:get)
139
+ .with(DummyJob.waiting_room_redis_key)
140
+ .and_return('0')
141
+ expect(DummyJob.repush('args')).to eq(true)
109
142
  end
110
143
 
111
- it "should return false if there were performs left" do
112
- Resque.redis.should_receive(:get).with(DummyJob.waiting_room_redis_key).and_return('1')
113
- DummyJob.repush('args').should == false
144
+ it 'should return false if there were performs left' do
145
+ expect(Resque.redis).to receive(:get)
146
+ .with(DummyJob.waiting_room_redis_key)
147
+ .and_return('1')
148
+ expect(DummyJob.repush('args')).to eq(false)
114
149
  end
115
150
  end
116
-
117
151
  end
118
-
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,15 @@
1
- require 'spork'
2
1
  require 'resque'
2
+ require 'mock_redis'
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'resque-waiting-room'))
4
4
 
5
- Spork.prefork do
6
- spec_dir = File.dirname(__FILE__)
7
- lib_dir = File.expand_path(File.join(spec_dir, '..', 'lib'))
8
- $:.unshift(lib_dir)
9
- $:.uniq!
10
- RSpec.configure do |config|
11
- config.mock_framework = :rspec
12
- end
13
-
14
- # Require ruby files in support dir.
15
- Dir[File.expand_path('spec/support/*.rb')].each { |file| require file }
5
+ RSpec.configure do |config|
6
+ config.mock_framework = :rspec
16
7
  end
8
+
9
+ puts 'Using a mock Redis'
10
+ r = MockRedis.new host: "localhost", port: 9736, db: 0
11
+ $mock_redis = Redis::Namespace.new :resque, redis: r
12
+ Resque.redis = $mock_redis
13
+
14
+ # Require ruby files in support dir.
15
+ Dir[File.expand_path('spec/support/*.rb')].each { |file| require file }
@@ -4,5 +4,5 @@ class DummyJob
4
4
  extend Resque::Plugins::WaitingRoom
5
5
  can_be_performed times: 10, period: 30
6
6
 
7
- def self.perform(*args); end
7
+ def self.perform(*_); end
8
8
  end
@@ -0,0 +1,27 @@
1
+ RSpec::Matchers.define :be_only_performed do |expected_options|
2
+ match do |actual_job_class|
3
+ raise ArgumentError, 'Need :times, and :period' unless [:times, :period].all? { |k| expected_options.keys.include? k }
4
+ expected_period = expected_options[:period]
5
+ expected_times = expected_options[:times]
6
+ actual_job_class = actual_job_class.class unless actual_job_class.kind_of?(Class)
7
+ unless actual_job_class.singleton_class.ancestors.include?(Resque::Plugins::WaitingRoom)
8
+ raise ArgumentError, 'waiting room matcher used on non resque-job'
9
+ end
10
+ [actual_job_class.instance_variable_get(:@period) == expected_period,
11
+ actual_job_class.instance_variable_get(:@max_performs) == expected_times].all?
12
+ end
13
+
14
+ failure_message do |actual_job_class|
15
+ actual_times = actual_job_class.instance_variable_get(:@max_performs)
16
+ actual_period = actual_job_class.instance_variable_get(:@period)
17
+ "expected #{actual_job_class} to have defined can_be_performed times: #{expected_options[:times]} period: #{expected_options[:period]}, got can_be_performed times: #{actual_times} period: #{actual_times}"
18
+ end
19
+
20
+ failure_message_when_negated do |actual|
21
+ "expected #{actual_job_class} to have NOT defined can_be_performed times: #{expected_options[:times]} period: #{expected_options[:period]}"
22
+ end
23
+
24
+ description do
25
+ "be performed at most #{expected_options[:times]} in #{expected_options[:period]} seconds"
26
+ end
27
+ end
metadata CHANGED
@@ -1,115 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-waiting-room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Julien Blanchard
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-13 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- requirement: &70112971736560 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 0.9.2.2
19
+ version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70112971736560
25
- - !ruby/object:Gem::Dependency
26
- name: resque
27
- requirement: &70112971735960 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ~>
24
+ - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 1.19.0
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70112971735960
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &70112971735380 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: 2.8.0
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70112971735380
26
+ version: '0'
47
27
  - !ruby/object:Gem::Dependency
48
- name: fuubar
49
- requirement: &70112971734900 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 1.0.0
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70112971734900
58
- - !ruby/object:Gem::Dependency
59
- name: spork
60
- requirement: &70112971734380 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ~>
64
- - !ruby/object:Gem::Version
65
- version: 0.9.0
66
- type: :development
67
- prerelease: false
68
- version_requirements: *70112971734380
69
- - !ruby/object:Gem::Dependency
70
- name: guard
71
- requirement: &70112971733860 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ~>
75
- - !ruby/object:Gem::Version
76
- version: 0.10.0
77
- type: :development
78
- prerelease: false
79
- version_requirements: *70112971733860
80
- - !ruby/object:Gem::Dependency
81
- name: guard-rspec
82
- requirement: &70112971733260 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ~>
86
- - !ruby/object:Gem::Version
87
- version: 0.6.0
88
- type: :development
89
- prerelease: false
90
- version_requirements: *70112971733260
91
- - !ruby/object:Gem::Dependency
92
- name: guard-spork
93
- requirement: &70112971732640 !ruby/object:Gem::Requirement
94
- none: false
28
+ name: resque
29
+ requirement: !ruby/object:Gem::Requirement
95
30
  requirements:
96
- - - ~>
31
+ - - ">="
97
32
  - !ruby/object:Gem::Version
98
- version: 0.3.0
33
+ version: '0'
99
34
  type: :development
100
35
  prerelease: false
101
- version_requirements: *70112971732640
102
- - !ruby/object:Gem::Dependency
103
- name: rb-fsevent
104
- requirement: &70112971731760 !ruby/object:Gem::Requirement
105
- none: false
36
+ version_requirements: !ruby/object:Gem::Requirement
106
37
  requirements:
107
- - - ~>
38
+ - - ">="
108
39
  - !ruby/object:Gem::Version
109
- version: 0.4.3.1
110
- type: :development
111
- prerelease: false
112
- version_requirements: *70112971731760
40
+ version: '0'
113
41
  description: Throttle your Resque jobs
114
42
  email:
115
43
  - julien@sideburns.eu
@@ -117,11 +45,11 @@ executables: []
117
45
  extensions: []
118
46
  extra_rdoc_files: []
119
47
  files:
120
- - .gitignore
121
- - .rbenv-version
122
- - .rspec
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".ruby-version"
51
+ - ".travis.yml"
123
52
  - Gemfile
124
- - Guardfile
125
53
  - LICENSE
126
54
  - README.markdown
127
55
  - Rakefile
@@ -134,33 +62,33 @@ files:
134
62
  - spec/resque/plugins/waiting_room_spec.rb
135
63
  - spec/spec_helper.rb
136
64
  - spec/support/dummy_job.rb
65
+ - spec/support/matchers.rb
137
66
  homepage: https://www.github.com/julienXX/resque-waiting-room
138
67
  licenses: []
68
+ metadata: {}
139
69
  post_install_message:
140
70
  rdoc_options: []
141
71
  require_paths:
142
72
  - lib
143
73
  required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
74
  requirements:
146
- - - ! '>='
75
+ - - ">="
147
76
  - !ruby/object:Gem::Version
148
77
  version: '0'
149
78
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
79
  requirements:
152
- - - ! '>='
80
+ - - ">="
153
81
  - !ruby/object:Gem::Version
154
82
  version: '0'
155
83
  requirements: []
156
84
  rubyforge_project: resque-waiting-room
157
- rubygems_version: 1.8.11
85
+ rubygems_version: 2.2.2
158
86
  signing_key:
159
- specification_version: 3
87
+ specification_version: 4
160
88
  summary: Put your Resque jobs in a waiting room
161
89
  test_files:
162
90
  - spec/resque/plugins/job_spec.rb
163
91
  - spec/resque/plugins/waiting_room_spec.rb
164
92
  - spec/spec_helper.rb
165
93
  - spec/support/dummy_job.rb
166
- has_rdoc:
94
+ - spec/support/matchers.rb
data/.rbenv-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p0
data/Guardfile DELETED
@@ -1,8 +0,0 @@
1
- guard 'rspec', :version => 2, :cli => "--drb --format Fuubar --color" do
2
- watch('lib/resque/plugins/job.rb')
3
- watch('lib/resque/plugins/waiting_room.rb')
4
- watch('spec/resque/plugins/job_spec.rb')
5
- watch('spec/resque/plugins/waiting_room_spec.rb')
6
- watch('spec/spec_helper.rb')
7
- end
8
-