resque-pause 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -4
- data/Gemfile.lock +54 -52
- data/LICENSE +20 -0
- data/README.md +5 -2
- data/Rakefile +2 -0
- data/lib/resque-pause/plugins/pause.rb +0 -1
- data/lib/resque-pause/server.rb +1 -2
- data/lib/resque_pause_helper.rb +20 -5
- data/lib/version.rb +1 -1
- data/resque-pause.gemspec +1 -0
- data/spec/redis-test.conf +1 -8
- data/spec/resque-pause/plugins/pause_spec.rb +11 -11
- data/spec/resque-web_spec.rb +14 -14
- data/spec/resque_pause_helper_spec.rb +17 -35
- data/spec/spec_helper.rb +11 -7
- metadata +86 -91
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa53cc76d2dea849b41cb3af8e9e3c855bbe64e9
|
4
|
+
data.tar.gz: 5988024024f1cbc5281d237993a709aab47668ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2dccaec7ed9e26b9f61a8c47732a9b82e3ed90e67814655d10241a14b856372b2856b5c24f5f8e26c947cf132618feff8e70217e7b87f7abd5039b60940790f
|
7
|
+
data.tar.gz: a9efbe8ed2763e602bd37c09241fd1721e396586fb473383587d2dabc7609f0f4aa39084807946ed3eddb78e34abbad8c6530533dd3be555ecd2f297c838b178
|
data/Gemfile
CHANGED
@@ -3,12 +3,14 @@ source "http://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in resque-pause.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
gem "rake"
|
7
|
+
|
6
8
|
group :test, :development do
|
7
|
-
platforms :
|
8
|
-
gem "
|
9
|
+
platforms :mri_19, :mri_20 do
|
10
|
+
gem "debugger"
|
9
11
|
end
|
10
12
|
|
11
|
-
platforms :
|
12
|
-
gem "
|
13
|
+
platforms :mri_21 do
|
14
|
+
gem "byebug"
|
13
15
|
end
|
14
16
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,73 +1,75 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
resque-pause (0.0
|
4
|
+
resque-pause (0.1.0)
|
5
|
+
multi_json (~> 1.0)
|
5
6
|
resque (>= 1.9.10)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
9
10
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ruby_core_source (
|
18
|
-
|
19
|
-
|
11
|
+
byebug (3.2.0)
|
12
|
+
columnize (~> 0.8)
|
13
|
+
debugger-linecache (~> 1.2)
|
14
|
+
columnize (0.8.9)
|
15
|
+
debugger (1.6.8)
|
16
|
+
columnize (>= 0.3.1)
|
17
|
+
debugger-linecache (~> 1.2.0)
|
18
|
+
debugger-ruby_core_source (~> 1.3.5)
|
19
|
+
debugger-linecache (1.2.0)
|
20
|
+
debugger-ruby_core_source (1.3.5)
|
21
|
+
diff-lcs (1.2.5)
|
22
|
+
docile (1.1.5)
|
23
|
+
mono_logger (1.1.0)
|
24
|
+
multi_json (1.10.1)
|
25
|
+
rack (1.5.2)
|
26
|
+
rack-protection (1.5.3)
|
27
|
+
rack
|
28
|
+
rack-test (0.6.2)
|
20
29
|
rack (>= 1.0)
|
21
|
-
|
22
|
-
redis (
|
23
|
-
redis-namespace (
|
24
|
-
redis (
|
25
|
-
resque (1.
|
26
|
-
|
27
|
-
|
30
|
+
rake (10.3.2)
|
31
|
+
redis (3.1.0)
|
32
|
+
redis-namespace (1.5.1)
|
33
|
+
redis (~> 3.0, >= 3.0.4)
|
34
|
+
resque (1.25.2)
|
35
|
+
mono_logger (~> 1.0)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
redis-namespace (~> 1.3)
|
28
38
|
sinatra (>= 0.9.2)
|
29
39
|
vegas (~> 0.1.2)
|
30
|
-
rspec (
|
31
|
-
rspec-core (~>
|
32
|
-
rspec-expectations (~>
|
33
|
-
rspec-mocks (~>
|
34
|
-
rspec-core (
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
simplecov (0.4.2)
|
54
|
-
simplecov-html (~> 0.4.4)
|
55
|
-
simplecov-html (0.4.5)
|
56
|
-
sinatra (1.2.6)
|
57
|
-
rack (~> 1.1)
|
58
|
-
tilt (>= 1.2.2, < 2.0)
|
59
|
-
tilt (1.3.2)
|
60
|
-
vegas (0.1.8)
|
40
|
+
rspec (3.0.0)
|
41
|
+
rspec-core (~> 3.0.0)
|
42
|
+
rspec-expectations (~> 3.0.0)
|
43
|
+
rspec-mocks (~> 3.0.0)
|
44
|
+
rspec-core (3.0.3)
|
45
|
+
rspec-support (~> 3.0.0)
|
46
|
+
rspec-expectations (3.0.3)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.0.0)
|
49
|
+
rspec-mocks (3.0.3)
|
50
|
+
rspec-support (~> 3.0.0)
|
51
|
+
rspec-support (3.0.3)
|
52
|
+
simplecov (0.9.0)
|
53
|
+
docile (~> 1.1.0)
|
54
|
+
multi_json
|
55
|
+
simplecov-html (~> 0.8.0)
|
56
|
+
simplecov-html (0.8.0)
|
57
|
+
sinatra (1.4.5)
|
58
|
+
rack (~> 1.4)
|
59
|
+
rack-protection (~> 1.4)
|
60
|
+
tilt (~> 1.3, >= 1.3.4)
|
61
|
+
tilt (1.4.1)
|
62
|
+
vegas (0.1.11)
|
61
63
|
rack (>= 1.0.0)
|
62
64
|
|
63
65
|
PLATFORMS
|
64
66
|
ruby
|
65
67
|
|
66
68
|
DEPENDENCIES
|
69
|
+
byebug
|
70
|
+
debugger
|
67
71
|
rack-test
|
68
|
-
|
72
|
+
rake
|
69
73
|
resque-pause!
|
70
74
|
rspec (>= 2.3.0)
|
71
|
-
ruby-debug
|
72
|
-
ruby-debug19
|
73
75
|
simplecov (>= 0.4.2)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) Wandenberg Peixoto (wandenberg@gmail.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/resque-pause/server.rb
CHANGED
@@ -6,7 +6,6 @@ require File.expand_path(File.join('../','resque_pause_helper'), File.dirname(__
|
|
6
6
|
# Structure has been borrowed from ResqueScheduler.
|
7
7
|
module ResquePause
|
8
8
|
module Server
|
9
|
-
include Resque::Helpers
|
10
9
|
|
11
10
|
def self.erb_path(filename)
|
12
11
|
File.join(File.dirname(__FILE__), 'server', 'views', filename)
|
@@ -43,7 +42,7 @@ module ResquePause
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
content_type :json
|
46
|
-
encode(:queue_name => params['queue_name'], :paused => pause)
|
45
|
+
ResquePauseHelper.encode(:queue_name => params['queue_name'], :paused => pause)
|
47
46
|
end
|
48
47
|
|
49
48
|
get /pause\/public\/([a-z]+\.[a-z]+)/ do
|
data/lib/resque_pause_helper.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
# OkJson won't work because it doesn't serialize symbols
|
4
|
+
# in the same way yajl and json do.
|
5
|
+
if MultiJson.respond_to?(:adapter)
|
6
|
+
raise "Please install the yajl-ruby or json gem" if MultiJson.adapter.to_s == 'MultiJson::Adapters::OkJson'
|
7
|
+
elsif MultiJson.respond_to?(:engine)
|
8
|
+
raise "Please install the yajl-ruby or json gem" if MultiJson.engine.to_s == 'MultiJson::Engines::OkJson'
|
9
|
+
end
|
10
|
+
|
1
11
|
module ResquePauseHelper
|
2
12
|
class << self
|
3
13
|
def paused?(queue)
|
@@ -13,11 +23,7 @@ module ResquePauseHelper
|
|
13
23
|
end
|
14
24
|
|
15
25
|
def enqueue_job(args)
|
16
|
-
Resque.redis.lpush("queue:#{args[:queue]}",
|
17
|
-
end
|
18
|
-
|
19
|
-
def dequeue_job(args)
|
20
|
-
Resque.redis.lpop("queue:#{args[:queue]}")
|
26
|
+
Resque.redis.lpush("queue:#{args[:queue]}", ResquePauseHelper.encode(:class => args[:class].to_s, :args => args[:args]))
|
21
27
|
end
|
22
28
|
|
23
29
|
def check_paused(args)
|
@@ -26,5 +32,14 @@ module ResquePauseHelper
|
|
26
32
|
raise Resque::Job::DontPerform.new "Queue #{args[:queue]} is paused!"
|
27
33
|
end
|
28
34
|
end
|
35
|
+
|
36
|
+
# Given a Ruby object, returns a string suitable for storage in a queue.
|
37
|
+
def encode(object)
|
38
|
+
if MultiJson.respond_to?(:dump) && MultiJson.respond_to?(:load)
|
39
|
+
MultiJson.dump object
|
40
|
+
else
|
41
|
+
MultiJson.encode object
|
42
|
+
end
|
43
|
+
end
|
29
44
|
end
|
30
45
|
end
|
data/lib/version.rb
CHANGED
data/resque-pause.gemspec
CHANGED
@@ -26,6 +26,7 @@ You can use this functionality to do some maintenance whithout kill workers, for
|
|
26
26
|
s.has_rdoc = false
|
27
27
|
|
28
28
|
s.add_dependency('resque', '>= 1.9.10')
|
29
|
+
s.add_dependency('multi_json', '~> 1.0')
|
29
30
|
|
30
31
|
s.add_development_dependency('rspec', '>= 2.3.0')
|
31
32
|
s.add_development_dependency('rack-test')
|
data/spec/redis-test.conf
CHANGED
@@ -6,7 +6,7 @@ daemonize yes
|
|
6
6
|
|
7
7
|
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
|
8
8
|
# You can specify a custom pid file location here.
|
9
|
-
pidfile
|
9
|
+
pidfile redis-test.pid
|
10
10
|
|
11
11
|
# Accept connections on the specified port, default is 6379
|
12
12
|
port 9736
|
@@ -106,10 +106,3 @@ databases 16
|
|
106
106
|
# errors for write operations, and this may even lead to DB inconsistency.
|
107
107
|
|
108
108
|
# maxmemory <bytes>
|
109
|
-
|
110
|
-
############################### ADVANCED CONFIG ###############################
|
111
|
-
|
112
|
-
# Glue small output buffers together in order to send small replies in a
|
113
|
-
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
114
|
-
# in terms of number of queries per second. Use 'yes' if unsure.
|
115
|
-
glueoutputbuf yes
|
@@ -15,35 +15,35 @@ describe Resque::Plugins::Pause do
|
|
15
15
|
|
16
16
|
it "should use at least resque version 1.9.10" do
|
17
17
|
major, minor, patch = Resque::Version.split('.')
|
18
|
-
major.to_i.
|
19
|
-
minor.to_i.
|
20
|
-
patch.to_i.
|
18
|
+
expect(major.to_i).to eq(1)
|
19
|
+
expect(minor.to_i).to be >= 9
|
20
|
+
expect(patch.to_i).to be >= 10 if minor.to_i == 9
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should execute the job when queue is not paused" do
|
24
24
|
Resque.enqueue(PauseJob)
|
25
|
-
PauseJob.
|
25
|
+
expect(PauseJob).to receive(:perform)
|
26
26
|
|
27
27
|
Resque.reserve('test').perform
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not execute the job when queue is paused" do
|
31
31
|
Resque.enqueue(PauseJob)
|
32
|
-
Resque.size('test').
|
32
|
+
expect(Resque.size('test')).to eq(1)
|
33
33
|
|
34
34
|
job = Resque.reserve('test')
|
35
35
|
ResquePauseHelper.pause('test')
|
36
36
|
job.perform
|
37
37
|
|
38
|
-
Resque.size('test').
|
38
|
+
expect(Resque.size('test')).to eq(1)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should not reserve the job when queue is paused" do
|
42
42
|
ResquePauseHelper.pause('test')
|
43
43
|
Resque.enqueue(PauseJob)
|
44
|
-
PauseJob.
|
44
|
+
expect(PauseJob).not_to receive(:perform)
|
45
45
|
|
46
|
-
Resque.reserve('test').
|
46
|
+
expect(Resque.reserve('test')).to be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should not change queued jobs when queue is paused" do
|
@@ -57,7 +57,7 @@ describe Resque::Plugins::Pause do
|
|
57
57
|
job.perform
|
58
58
|
|
59
59
|
remaining_jobs = Resque.redis.lrange('queue:test', 0, 2)
|
60
|
-
jobs.
|
60
|
+
expect(jobs).to eq(remaining_jobs)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should back to execute the job when queue is unpaused" do
|
@@ -66,11 +66,11 @@ describe Resque::Plugins::Pause do
|
|
66
66
|
job = Resque.reserve('test')
|
67
67
|
ResquePauseHelper.pause('test')
|
68
68
|
job.perform
|
69
|
-
Resque.size('test').
|
69
|
+
expect(Resque.size('test')).to eq(1)
|
70
70
|
|
71
71
|
ResquePauseHelper.unpause('test')
|
72
72
|
Resque.reserve('test').perform
|
73
|
-
Resque.size('test').
|
73
|
+
expect(Resque.size('test')).to eq(0)
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
data/spec/resque-web_spec.rb
CHANGED
@@ -18,56 +18,56 @@ describe ResquePause::Server do
|
|
18
18
|
|
19
19
|
it "should respond to /pause" do
|
20
20
|
get '/pause'
|
21
|
-
last_response.
|
21
|
+
expect(last_response).to be_ok
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should list all registered queues" do
|
25
25
|
get '/pause'
|
26
|
-
last_response.body.
|
27
|
-
last_response.body.
|
28
|
-
last_response.body.
|
26
|
+
expect(last_response.body).to include("queue1")
|
27
|
+
expect(last_response.body).to include("queue2")
|
28
|
+
expect(last_response.body).to include("queue3")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should check paused queues" do
|
32
32
|
ResquePauseHelper.pause("queue2")
|
33
33
|
|
34
34
|
get '/pause'
|
35
|
-
last_response.body.
|
36
|
-
last_response.body.
|
37
|
-
last_response.body.
|
35
|
+
expect(last_response.body).to include(%q{<input class="pause" type="checkbox" value="queue1" ></input>})
|
36
|
+
expect(last_response.body).to include(%q{<input class="pause" type="checkbox" value="queue2" checked></input>})
|
37
|
+
expect(last_response.body).to include(%q{<input class="pause" type="checkbox" value="queue3" ></input>})
|
38
38
|
end
|
39
39
|
|
40
40
|
|
41
41
|
it "should pause a queue" do
|
42
42
|
post "/pause", :queue_name => "queue3", :pause => true
|
43
43
|
|
44
|
-
ResquePauseHelper.paused?("queue3").
|
44
|
+
expect(ResquePauseHelper.paused?("queue3")).to be_truthy
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should return a json when pause a queue" do
|
48
48
|
post "/pause", :queue_name => "queue3", :pause => true
|
49
49
|
|
50
|
-
last_response.headers["Content-Type"].
|
51
|
-
last_response.body.
|
50
|
+
expect(last_response.headers["Content-Type"]).to eq("application/json")
|
51
|
+
expect(last_response.body).to eq({ :queue_name => "queue3", :paused => true }.to_json)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should unpause a queue" do
|
55
55
|
ResquePauseHelper.pause("queue2")
|
56
56
|
post "/pause", :queue_name => "queue2", :pause => false
|
57
57
|
|
58
|
-
ResquePauseHelper.paused?("queue2").
|
58
|
+
expect(ResquePauseHelper.paused?("queue2")).to be_falsey
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return a json when unpause a queue" do
|
62
62
|
post "/pause", :queue_name => "queue2", :pause => false
|
63
63
|
|
64
|
-
last_response.headers["Content-Type"].
|
65
|
-
last_response.body.
|
64
|
+
expect(last_response.headers["Content-Type"]).to eq("application/json")
|
65
|
+
expect(last_response.body).to eq({ :queue_name => "queue2", :paused => false }.to_json)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should return static files" do
|
69
69
|
get "/pause/public/pause.js"
|
70
|
-
last_response.body.
|
70
|
+
expect(last_response.body).to eq(File.read(File.expand_path('../lib/resque-pause/server/public/pause.js', File.dirname(__FILE__))))
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -13,13 +13,13 @@ describe ResquePauseHelper do
|
|
13
13
|
it "should return return false if don't have register on redis" do
|
14
14
|
Resque.redis.del "pause:queue:queue1"
|
15
15
|
|
16
|
-
subject.paused?("queue1").
|
16
|
+
expect(subject.paused?("queue1")).to be_falsey
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should return return true if have register on redis" do
|
20
20
|
Resque.redis.set "pause:queue:queue1", "AnyValue"
|
21
21
|
|
22
|
-
subject.paused?("queue1").
|
22
|
+
expect(subject.paused?("queue1")).to be_truthy
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -28,15 +28,15 @@ describe ResquePauseHelper do
|
|
28
28
|
Resque.redis.del "pause:queue:queue1"
|
29
29
|
subject.pause("queue1")
|
30
30
|
|
31
|
-
subject.paused?("queue1").
|
31
|
+
expect(subject.paused?("queue1")).to be_truthy
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should register again a registred queue" do
|
35
35
|
Resque.redis.set "pause:queue:queue1", "AnyValue"
|
36
36
|
expect { subject.pause("queue1") }.to_not raise_error
|
37
37
|
|
38
|
-
Resque.redis.get("pause:queue:queue1").
|
39
|
-
Resque.redis.get("pause:queue:queue1").
|
38
|
+
expect(Resque.redis.get("pause:queue:queue1")).not_to be_nil
|
39
|
+
expect(Resque.redis.get("pause:queue:queue1")).to be_truthy
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -45,14 +45,14 @@ describe ResquePauseHelper do
|
|
45
45
|
Resque.redis.del "pause:queue:queue1"
|
46
46
|
subject.unpause("queue1")
|
47
47
|
|
48
|
-
subject.paused?("queue1").
|
48
|
+
expect(subject.paused?("queue1")).to be_falsey
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should unregister a registred queue" do
|
52
52
|
Resque.redis.set "pause:queue:queue1", "AnyValue"
|
53
53
|
expect { subject.unpause("queue1") }.to_not raise_error
|
54
54
|
|
55
|
-
Resque.redis.get("pause:queue:queue1").
|
55
|
+
expect(Resque.redis.get("pause:queue:queue1")).to be_nil
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -62,7 +62,7 @@ describe ResquePauseHelper do
|
|
62
62
|
|
63
63
|
subject.enqueue_job(:queue => "queue1", :class => PauseJob, :args => nil)
|
64
64
|
|
65
|
-
Resque.redis.llen("queue:queue1").to_i.
|
65
|
+
expect(Resque.redis.llen("queue:queue1").to_i).to eq(1)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should enqueue on beginning of a queue" do
|
@@ -72,55 +72,37 @@ describe ResquePauseHelper do
|
|
72
72
|
|
73
73
|
jobs = Resque.redis.lrange('queue:queue1', 0, 10)
|
74
74
|
|
75
|
-
jobs.count.
|
76
|
-
jobs[0].
|
77
|
-
jobs[1].
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "when dequeue a job" do
|
82
|
-
it "should not get error when queue is empty" do
|
83
|
-
Resque.redis.del "queue:queue1"
|
84
|
-
|
85
|
-
expect { subject.dequeue_job(:queue => "queue1") }.to_not raise_error
|
86
|
-
|
87
|
-
subject.dequeue_job(:queue => "queue1").should be_nil
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should get the job on beginning of a queue" do
|
91
|
-
Resque.redis.lpush "queue:queue1", {:class => PauseJob, :args => [1, 2]}.to_json
|
92
|
-
Resque.redis.lpush "queue:queue1", {:class => PauseJob, :args => [1]}.to_json
|
93
|
-
|
94
|
-
job = subject.dequeue_job(:queue => "queue1")
|
95
|
-
job.should == {:class => PauseJob, :args => [1]}.to_json
|
75
|
+
expect(jobs.count).to eq(2)
|
76
|
+
expect(jobs[0]).to eq({:class => PauseJob, :args => [1]}.to_json)
|
77
|
+
expect(jobs[1]).to eq({:class => PauseJob, :args => [1, 2]}.to_json)
|
96
78
|
end
|
97
79
|
end
|
98
80
|
|
99
81
|
context "when checking if queue is paused" do
|
100
82
|
it "should check if queue is paused" do
|
101
|
-
subject.
|
83
|
+
expect(subject).to receive(:paused?).with("queue1")
|
102
84
|
|
103
85
|
subject.check_paused(:queue => "queue1")
|
104
86
|
end
|
105
87
|
|
106
88
|
it "should not raise error when queue is not paused" do
|
107
|
-
subject.
|
89
|
+
expect(subject).to receive(:paused?).with("queue1").and_return(false)
|
108
90
|
|
109
91
|
expect { subject.check_paused(:queue => "queue1") }.to_not raise_error
|
110
92
|
end
|
111
93
|
|
112
94
|
it "should raise error when queue is paused" do
|
113
|
-
subject.
|
114
|
-
subject.
|
95
|
+
allow(subject).to receive(:enqueue_job)
|
96
|
+
allow(subject).to receive(:paused?).with("queue1").and_return(true)
|
115
97
|
|
116
98
|
expect { subject.check_paused(:queue => "queue1") }.to raise_error(Resque::Job::DontPerform)
|
117
99
|
end
|
118
100
|
|
119
101
|
it "should enqueue the job again when queue is paused" do
|
120
|
-
subject.
|
102
|
+
allow(subject).to receive(:paused?).with("queue1").and_return(true)
|
121
103
|
|
122
104
|
args = {:queue => "queue1", :class => PauseJob, :args => [1, 2]}
|
123
|
-
subject.
|
105
|
+
expect(subject).to receive(:enqueue_job).with(args)
|
124
106
|
|
125
107
|
subject.check_paused(args) rescue nil
|
126
108
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -41,25 +41,29 @@ RSpec.configure do |config|
|
|
41
41
|
# config.mock_with :rr
|
42
42
|
config.mock_with :rspec
|
43
43
|
|
44
|
+
config.order = "random"
|
45
|
+
|
44
46
|
config.before(:suite) do
|
45
|
-
puts
|
47
|
+
puts '', 'Starting redis for testing at localhost:9736...', ''
|
48
|
+
FileUtils.rm_f('spec/redis-test.pid')
|
46
49
|
`redis-server #{File.dirname(File.expand_path(__FILE__))}/redis-test.conf`
|
47
50
|
pid = ''
|
48
51
|
while pid.empty? do
|
49
|
-
pid =
|
52
|
+
pid = File.read('spec/redis-test.pid').chomp rescue ''
|
50
53
|
end
|
51
54
|
Resque.redis = '127.0.0.1:9736'
|
52
55
|
end
|
53
56
|
|
54
57
|
config.before(:each) do
|
55
58
|
Resque.redis.flushall
|
56
|
-
Kernel.
|
59
|
+
allow(Kernel).to receive(:sleep)
|
57
60
|
end
|
58
61
|
|
59
62
|
config.after(:suite) do
|
60
|
-
pid =
|
61
|
-
puts '',
|
62
|
-
Process.kill(
|
63
|
-
|
63
|
+
pid = File.read('spec/redis-test.pid').chomp rescue ''
|
64
|
+
puts '', '', 'Killing test redis server...'
|
65
|
+
Process.kill('KILL', pid.to_i)
|
66
|
+
FileUtils.rm_f('spec/redis-test.pid')
|
67
|
+
FileUtils.rm_f('spec/dumb.rdb')
|
64
68
|
end
|
65
69
|
end
|
metadata
CHANGED
@@ -1,100 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-pause
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
version: 0.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Wandenberg Peixoto
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: resque
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.9.10
|
20
|
+
type: :runtime
|
22
21
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 1
|
30
|
-
- 9
|
31
|
-
- 10
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
32
26
|
version: 1.9.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
33
34
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
35
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
47
|
version: 2.3.0
|
48
48
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: rack-test
|
52
49
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
61
62
|
type: :development
|
62
|
-
version_requirements: *id003
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: simplecov
|
65
63
|
prerelease: false
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
75
|
version: 0.4.2
|
76
76
|
type: :development
|
77
|
-
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.4.2
|
78
83
|
description: |-
|
79
84
|
A Resque plugin to add functionality to pause resque jobs through the web interface.
|
80
|
-
|
85
|
+
|
81
86
|
Using a `pause` allows you to stop the job for a slice of time.
|
82
87
|
The job finish the process it are doing and don't get a new task to do,
|
83
88
|
until the queue is released.
|
84
89
|
You can use this functionality to do some maintenance whithout kill workers, for example.
|
85
|
-
email:
|
90
|
+
email:
|
86
91
|
- wandenberg@gmail.com
|
87
92
|
executables: []
|
88
|
-
|
89
93
|
extensions: []
|
90
|
-
|
91
94
|
extra_rdoc_files: []
|
92
|
-
|
93
|
-
files:
|
95
|
+
files:
|
94
96
|
- .gitignore
|
97
|
+
- .travis.yml
|
95
98
|
- Changelog.md
|
96
99
|
- Gemfile
|
97
100
|
- Gemfile.lock
|
101
|
+
- LICENSE
|
98
102
|
- README.md
|
99
103
|
- Rakefile
|
100
104
|
- lib/resque-pause.rb
|
@@ -111,37 +115,28 @@ files:
|
|
111
115
|
- spec/resque-web_spec.rb
|
112
116
|
- spec/resque_pause_helper_spec.rb
|
113
117
|
- spec/spec_helper.rb
|
114
|
-
|
115
|
-
homepage: ""
|
118
|
+
homepage: ''
|
116
119
|
licenses: []
|
117
|
-
|
120
|
+
metadata: {}
|
118
121
|
post_install_message:
|
119
122
|
rdoc_options: []
|
120
|
-
|
121
|
-
require_paths:
|
123
|
+
require_paths:
|
122
124
|
- lib
|
123
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
requirements:
|
134
|
-
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
segments:
|
137
|
-
- 0
|
138
|
-
version: "0"
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
139
135
|
requirements: []
|
140
|
-
|
141
136
|
rubyforge_project: resque-pause
|
142
|
-
rubygems_version:
|
137
|
+
rubygems_version: 2.2.2
|
143
138
|
signing_key:
|
144
|
-
specification_version:
|
145
|
-
summary: A Resque plugin to add functionality to pause resque jobs through the web
|
139
|
+
specification_version: 4
|
140
|
+
summary: A Resque plugin to add functionality to pause resque jobs through the web
|
141
|
+
interface.
|
146
142
|
test_files: []
|
147
|
-
|