resque-pause 0.1.0 → 0.2.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: fa53cc76d2dea849b41cb3af8e9e3c855bbe64e9
4
- data.tar.gz: 5988024024f1cbc5281d237993a709aab47668ca
3
+ metadata.gz: 556f2192f7d4152f2c36c6c9d025da63a284007b
4
+ data.tar.gz: 23889f55a4772fdae025deffb73f42f67f814526
5
5
  SHA512:
6
- metadata.gz: d2dccaec7ed9e26b9f61a8c47732a9b82e3ed90e67814655d10241a14b856372b2856b5c24f5f8e26c947cf132618feff8e70217e7b87f7abd5039b60940790f
7
- data.tar.gz: a9efbe8ed2763e602bd37c09241fd1721e396586fb473383587d2dabc7609f0f4aa39084807946ed3eddb78e34abbad8c6530533dd3be555ecd2f297c838b178
6
+ metadata.gz: e9a4cd7579bc9b8d502bdaa117c1b3194c8fb50c699b1d871a0f94ac9507bd607cecfd2c8894328d4dfc3d3e515ac34020e52ca5bb74f41cbcbbca4b3ac1386d
7
+ data.tar.gz: ff0095a087c12613175dfbf4edcf8201272192a466170a6f63f0eab54ea7b620d8cc51384b46bca30a631e7b5b2ee77420e33e996d14f99cecb73e9299bdc007
data/.gitignore CHANGED
@@ -4,3 +4,6 @@ pkg/*
4
4
  coverage/*
5
5
  .rvmrc
6
6
  .project
7
+ spec/dump.rdb
8
+ spec/stdout
9
+ vendor/*
data/Gemfile CHANGED
@@ -6,11 +6,11 @@ gemspec
6
6
  gem "rake"
7
7
 
8
8
  group :test, :development do
9
- platforms :mri_19, :mri_20 do
9
+ platforms :mri_19 do
10
10
  gem "debugger"
11
11
  end
12
12
 
13
- platforms :mri_21 do
13
+ platforms :mri_20, :mri_21 do
14
14
  gem "byebug"
15
15
  end
16
16
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- resque-pause (0.1.0)
4
+ resque-pause (0.2.0)
5
5
  multi_json (~> 1.0)
6
6
  resque (>= 1.9.10)
7
7
 
@@ -12,12 +12,7 @@ GEM
12
12
  columnize (~> 0.8)
13
13
  debugger-linecache (~> 1.2)
14
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
15
  debugger-linecache (1.2.0)
20
- debugger-ruby_core_source (1.3.5)
21
16
  diff-lcs (1.2.5)
22
17
  docile (1.1.5)
23
18
  mono_logger (1.1.0)
@@ -28,10 +23,10 @@ GEM
28
23
  rack-test (0.6.2)
29
24
  rack (>= 1.0)
30
25
  rake (10.3.2)
31
- redis (3.1.0)
32
- redis-namespace (1.5.1)
26
+ redis (3.3.0)
27
+ redis-namespace (1.5.2)
33
28
  redis (~> 3.0, >= 3.0.4)
34
- resque (1.25.2)
29
+ resque (1.26.0)
35
30
  mono_logger (~> 1.0)
36
31
  multi_json (~> 1.0)
37
32
  redis-namespace (~> 1.3)
@@ -54,10 +49,10 @@ GEM
54
49
  multi_json
55
50
  simplecov-html (~> 0.8.0)
56
51
  simplecov-html (0.8.0)
57
- sinatra (1.4.5)
58
- rack (~> 1.4)
52
+ sinatra (1.4.7)
53
+ rack (~> 1.5)
59
54
  rack-protection (~> 1.4)
60
- tilt (~> 1.3, >= 1.3.4)
55
+ tilt (>= 1.3, < 3)
61
56
  tilt (1.4.1)
62
57
  vegas (0.1.11)
63
58
  rack (>= 1.0.0)
@@ -73,3 +68,6 @@ DEPENDENCIES
73
68
  resque-pause!
74
69
  rspec (>= 2.3.0)
75
70
  simplecov (>= 0.4.2)
71
+
72
+ BUNDLED WITH
73
+ 1.12.4
data/README.md CHANGED
@@ -18,20 +18,57 @@ Usage / Examples
18
18
 
19
19
  ### Single Job Instance
20
20
 
21
- require 'resque-pause'
21
+ ```ruby
22
+ require 'resque-pause'
23
+
24
+ class UpdateNetworkGraph
25
+ extend Resque::Plugins::Pause
26
+ @queue = :network_graph
27
+
28
+ def self.perform(repo_id)
29
+ heavy_lifting
30
+ end
31
+ end
32
+ ```
33
+
34
+ ### Pausing Individual Queues
35
+
36
+ To pause the queue:
37
+
38
+ ```ruby
39
+ ResquePauseHelper.pause(:network_graph)
40
+ ```
41
+
42
+ Then, to unpause the queue:
43
+
44
+ ```ruby
45
+ ResquePauseHelper.unpause(:network_graph)
46
+ ```
47
+
48
+ Single-queue pause is achieved by storing a pause/queue key in Redis.
49
+
22
50
 
23
- class UpdateNetworkGraph
24
- extend Resque::Plugins::Pause
25
- @queue = :network_graph
51
+ ### Global Pause
26
52
 
27
- def self.perform(repo_id)
28
- heavy_lifting
29
- end
30
- end
53
+ You can also pause all the queues at once.
31
54
 
32
- Pause is achieved by storing a pause/queue key in Redis.
55
+ To switch on a global pause:
33
56
 
34
- Default behaviour...
57
+ ```ruby
58
+ ResquePauseHelper.global_pause()
59
+ ```
60
+
61
+ Then, to remove a global pause:
62
+
63
+ ```ruby
64
+ ResquePauseHelper.global_unpause()
65
+ ```
66
+
67
+ This global pause doesn't interact with any pauses on individual queues. That means, switching the global pause on and off should preserve whatever pauses you might have in place before and even during the global pause period.
68
+
69
+ An anology would be with light switches and circuit breakers. Positioning light switches is like pausing individual queues. Whatever their position before you flip the breaker (impose a global pause). They'll maintain that position after the global pause.
70
+
71
+ ### Default behaviour
35
72
 
36
73
  * When the job instance try to execute and the queue is paused, the job is paused for a slice of time.
37
74
  * If the queue still paused after this time the job will abort and will be enqueued again with the same arguments.
@@ -43,7 +80,7 @@ Resque-Web integration
43
80
  You have to load ResquePause to enable the Pause tab.
44
81
 
45
82
  ```ruby
46
- require 'resque-pause/server'
83
+ require 'resque-pause/server'
47
84
  ```
48
85
 
49
86
  Customise & Extend
@@ -58,23 +95,34 @@ By default the time is 10 seconds.
58
95
 
59
96
  You can define the attribute in your job class in seconds.
60
97
 
61
- class UpdateNetworkGraph
62
- extend Resque::Plugins::Pause
63
- @queue = :network_graph
64
- @pause_check_interval = 30
65
-
66
- def self.perform(repo_id)
67
- heavy_lifting
68
- end
69
- end
98
+ ```ruby
99
+ class UpdateNetworkGraph
100
+ extend Resque::Plugins::Pause
101
+ @queue = :network_graph
102
+ @pause_check_interval = 30
103
+
104
+ def self.perform(repo_id)
105
+ heavy_lifting
106
+ end
107
+ end
108
+ ```
70
109
 
71
110
  The above modification will ensure the job will wait for 30 seconds before abort.
72
111
 
112
+ ### Global pause Redis key
113
+
114
+ To change the exact key that will be put into redis to signal a global pause, use the `global_pause_key` config
115
+
116
+ ````ruby
117
+ ResquePauseHelper.global_pause_key = "my_custom_key"
118
+ ````
73
119
 
74
120
  Install
75
121
  =======
76
122
 
77
- $ gem install resque-pause
123
+ ```bash
124
+ $ gem install resque-pause
125
+ ```
78
126
 
79
127
  [rq]: http://github.com/defunkt/resque
80
128
  [resque-pause]: https://github.com/wandenberg/resque-pause
@@ -23,22 +23,46 @@ module ResquePause
23
23
  def paused?(queue)
24
24
  ResquePauseHelper.paused?(queue)
25
25
  end
26
+
27
+ def global_paused?
28
+ ResquePauseHelper.global_paused?
29
+ end
26
30
  end
27
31
 
28
32
  mime_type :json, 'application/json'
29
33
 
30
34
  get '/pause' do
31
- erb File.read(ResquePause::Server.erb_path('pause.erb'))
35
+ case request.accept.first
36
+ when /json/
37
+ content_type :json
38
+ resque.queues.inject({"GLOBAL_PAUSE" => ResquePauseHelper.global_paused?}) do |pause_status, queue|
39
+ pause_status[queue] = ResquePauseHelper.paused?(queue)
40
+ pause_status
41
+ end.to_json
42
+ else
43
+ erb File.read(ResquePause::Server.erb_path('pause.erb'))
44
+ end
32
45
  end
33
46
 
34
47
  post '/pause' do
35
- pause = params['pause'] == "true"
48
+ params.merge!(MultiJson.load(request.body.read.to_s)) if /json/ =~ request.content_type
49
+
50
+ pause = params['pause'].to_s == "true"
36
51
 
37
52
  unless params['queue_name'].empty?
38
- if pause
39
- ResquePauseHelper.pause(params['queue_name'])
53
+ case params['queue_name']
54
+ when "GLOBAL_PAUSE"
55
+ if pause
56
+ ResquePauseHelper.global_pause
57
+ else
58
+ ResquePauseHelper.global_unpause
59
+ end
40
60
  else
41
- ResquePauseHelper.unpause(params['queue_name'])
61
+ if pause
62
+ ResquePauseHelper.pause(params['queue_name'])
63
+ else
64
+ ResquePauseHelper.unpause(params['queue_name'])
65
+ end
42
66
  end
43
67
  end
44
68
  content_type :json
@@ -8,7 +8,12 @@ jQuery(document).ready(function($) {
8
8
  data: data,
9
9
  async: false,
10
10
  cache: false,
11
- success: function() { return true; },
11
+ success: function() {
12
+ if (queue.val() === "GLOBAL_PAUSE") {
13
+ location.reload();
14
+ }
15
+ return true;
16
+ },
12
17
  error: function() { return false; },
13
18
  dataType: 'json'
14
19
  });
@@ -15,4 +15,10 @@
15
15
  <td class='size'><%= resque.size queue %></td>
16
16
  </tr>
17
17
  <% end %>
18
+ <tr><td class='queue'>&nbsp;</td><td class='status'></td><td class='size'></td></tr>
19
+ <tr>
20
+ <td class='queue'><b><i>GLOBAL PAUSE</i></b></td>
21
+ <td class='status'><input class="pause" type="checkbox" value="GLOBAL_PAUSE" <%= "checked" if global_paused? %>></input></td>
22
+ <td class='size'>-</td>
23
+ </tr>
18
24
  </table>
@@ -10,8 +10,10 @@ end
10
10
 
11
11
  module ResquePauseHelper
12
12
  class << self
13
+ DEFAULT_GLOBAL_PAUSE_KEY = "pause:all"
14
+
13
15
  def paused?(queue)
14
- !Resque.redis.get("pause:queue:#{queue}").nil?
16
+ !Resque.redis.mget("pause:queue:#{queue}", global_pause_key).all?(&:nil?)
15
17
  end
16
18
 
17
19
  def pause(queue)
@@ -22,6 +24,18 @@ module ResquePauseHelper
22
24
  Resque.redis.del "pause:queue:#{queue}"
23
25
  end
24
26
 
27
+ def global_pause()
28
+ Resque.redis.set global_pause_key, true
29
+ end
30
+
31
+ def global_unpause()
32
+ Resque.redis.del global_pause_key
33
+ end
34
+
35
+ def global_paused?()
36
+ !!Resque.redis.get(global_pause_key)
37
+ end
38
+
25
39
  def enqueue_job(args)
26
40
  Resque.redis.lpush("queue:#{args[:queue]}", ResquePauseHelper.encode(:class => args[:class].to_s, :args => args[:args]))
27
41
  end
@@ -41,5 +55,13 @@ module ResquePauseHelper
41
55
  MultiJson.encode object
42
56
  end
43
57
  end
58
+
59
+ def global_pause_key=(key)
60
+ @global_pause_key = key
61
+ end
62
+
63
+ def global_pause_key
64
+ @global_pause_key ||= DEFAULT_GLOBAL_PAUSE_KEY
65
+ end
44
66
  end
45
67
  end
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module Pause
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -46,6 +46,83 @@ describe Resque::Plugins::Pause do
46
46
  expect(Resque.reserve('test')).to be_nil
47
47
  end
48
48
 
49
+ it "should execute the job when queue is unpaused after being paused" do
50
+ Resque.enqueue(PauseJob)
51
+ expect(Resque.size('test')).to eq(1)
52
+
53
+ job = Resque.reserve('test')
54
+ ResquePauseHelper.pause('test')
55
+ job.perform
56
+ expect(Resque.size('test')).to eq(1)
57
+
58
+ ResquePauseHelper.unpause('test')
59
+
60
+ expect(PauseJob).to receive(:perform)
61
+ Resque.reserve('test').perform
62
+ expect(Resque.size('test')).to eq(0)
63
+ end
64
+
65
+ it "should not reserve the job when global pause is on" do
66
+ Resque.enqueue(PauseJob)
67
+ ResquePauseHelper.global_pause()
68
+ expect(PauseJob).not_to receive(:perform)
69
+
70
+ expect(Resque.reserve('test')).to be_nil
71
+ end
72
+
73
+ it "should not execute the job when the global pause is on" do
74
+ Resque.enqueue(PauseJob)
75
+ expect(Resque.size('test')).to eq(1)
76
+
77
+ job = Resque.reserve('test')
78
+ ResquePauseHelper.global_pause()
79
+ job.perform
80
+
81
+ expect(Resque.size('test')).to eq(1)
82
+ end
83
+
84
+ it "should execute the job when the global pause was switched on and then off" do
85
+ Resque.enqueue(PauseJob)
86
+ expect(Resque.size('test')).to eq(1)
87
+
88
+ job = Resque.reserve('test')
89
+ ResquePauseHelper.global_pause()
90
+ job.perform
91
+ expect(Resque.size('test')).to eq(1)
92
+
93
+ ResquePauseHelper.global_unpause()
94
+
95
+ expect(PauseJob).to receive(:perform)
96
+ Resque.reserve('test').perform
97
+ expect(Resque.size('test')).to eq(0)
98
+ end
99
+
100
+ it "should not execute the job when the queue is paused, and then the global pause is switched on and then back off" do
101
+ Resque.enqueue(PauseJob)
102
+ expect(Resque.size('test')).to eq(1)
103
+
104
+ job = Resque.reserve('test')
105
+ ResquePauseHelper.pause('test')
106
+
107
+ ResquePauseHelper.global_pause()
108
+ ResquePauseHelper.global_unpause()
109
+
110
+ job.perform
111
+
112
+ expect(Resque.size('test')).to eq(1)
113
+ end
114
+
115
+ it "should not reserve the job when the queue is paused, and then the global pause is switched on and then back off" do
116
+ Resque.enqueue(PauseJob)
117
+ ResquePauseHelper.pause('test')
118
+ ResquePauseHelper.global_pause()
119
+ ResquePauseHelper.global_unpause()
120
+
121
+ expect(PauseJob).not_to receive(:perform)
122
+
123
+ expect(Resque.reserve('test')).to be_nil
124
+ end
125
+
49
126
  it "should not change queued jobs when queue is paused" do
50
127
  Resque.enqueue(PauseJob, 1)
51
128
  Resque.enqueue(PauseJob, 2)
@@ -73,4 +150,57 @@ describe Resque::Plugins::Pause do
73
150
  expect(Resque.size('test')).to eq(0)
74
151
  end
75
152
 
153
+ it "should allow the global pause key to be configurable" do
154
+ pause_key = "my_new_pause_key"
155
+
156
+ ResquePauseHelper.global_pause_key = pause_key
157
+
158
+ Resque.enqueue(PauseJob)
159
+ ResquePauseHelper.global_pause()
160
+
161
+ expect(Resque.redis.get(pause_key)).not_to be_nil
162
+ end
163
+
164
+ it "should still handle global pauses with a client-configured key" do
165
+ pause_key = "my_new_pause_key"
166
+
167
+ ResquePauseHelper.global_pause_key = pause_key
168
+
169
+ Resque.enqueue(PauseJob)
170
+ expect(Resque.size('test')).to eq(1)
171
+
172
+ job = Resque.reserve('test')
173
+ ResquePauseHelper.global_pause()
174
+ job.perform
175
+
176
+ expect(Resque.size('test')).to eq(1)
177
+ end
178
+
179
+ it "should still handle switching global pauses back off with a client-configured key" do
180
+ pause_key = "my_new_pause_key"
181
+
182
+ ResquePauseHelper.global_pause_key = pause_key
183
+
184
+ Resque.enqueue(PauseJob)
185
+ expect(Resque.size('test')).to eq(1)
186
+
187
+ job = Resque.reserve('test')
188
+ ResquePauseHelper.global_pause()
189
+ job.perform
190
+ expect(Resque.size('test')).to eq(1)
191
+
192
+ ResquePauseHelper.global_unpause()
193
+
194
+ expect(PauseJob).to receive(:perform)
195
+ Resque.reserve('test').perform
196
+ expect(Resque.size('test')).to eq(0)
197
+ end
198
+
199
+ it "should indicate whether the global pause is on" do
200
+ expect(ResquePauseHelper.global_paused?).to be false
201
+ ResquePauseHelper.global_pause()
202
+ expect(ResquePauseHelper.global_paused?).to be true
203
+ ResquePauseHelper.global_unpause()
204
+ expect(ResquePauseHelper.global_paused?).to be false
205
+ end
76
206
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-pause
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wandenberg Peixoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-23 00:00:00.000000000 Z
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.9.10
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.9.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.3.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.3.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack-test
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.4.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.4.2
83
83
  description: |-
@@ -93,8 +93,8 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
- - .gitignore
97
- - .travis.yml
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
98
  - Changelog.md
99
99
  - Gemfile
100
100
  - Gemfile.lock
@@ -124,17 +124,17 @@ require_paths:
124
124
  - lib
125
125
  required_ruby_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - '>='
127
+ - - ">="
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
- - - '>='
132
+ - - ">="
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project: resque-pause
137
- rubygems_version: 2.2.2
137
+ rubygems_version: 2.5.1
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: A Resque plugin to add functionality to pause resque jobs through the web