resque_manager 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
3
+
4
+ class DummyClass
5
+ include ResqueScheduler
6
+ end
7
+
8
+ class ResqueSchedulerTest < Test::Unit::TestCase
9
+ context 'ResqueSchedule' do
10
+ setup { @dummy = DummyClass.new }
11
+
12
+ context '#schedule=' do
13
+ should 'always raise a RunTimeError' do
14
+ err = assert_raise(RuntimeError) { @dummy.schedule = {} }
15
+ assert_match /not implemented/, err.message
16
+ end
17
+ end
18
+
19
+ context '#schedule' do
20
+ should 'return a hash' do
21
+ hash = { make_tea: { every: '1m' }, about: { name: 'green' } }
22
+ Resque.stubs(:list_range).returns([hash])
23
+ hash_response = @dummy.schedule
24
+ assert_equal hash[:make_tea], hash_response[:make_tea]
25
+ assert_equal hash[:about], hash_response[:about]
26
+ end
27
+ end
28
+
29
+ context '.start' do
30
+ should 'run rake task resque:scheduler when Rails.env is test' do
31
+ Thread.expects(:new)
32
+ ResqueScheduler.start('0.0.0.0')
33
+ end
34
+
35
+ should 'run rake task resque:scheduler when Rails.env is anything other than test or development' do
36
+ Rails.expects(:env).returns('prod')
37
+ Thread.expects(:new).with('0.0.0.0')
38
+ ResqueScheduler.start('0.0.0.0')
39
+ end
40
+ end
41
+
42
+ context '.quit' do
43
+ should 'run the rake task resque:quit scheduler when Rails.env is anything other than test or development' do
44
+ ResqueScheduler.expects(:system).with('rake resque:quit_scheduler')
45
+ ResqueScheduler.quit('0.0.0.0')
46
+ end
47
+
48
+ should 'run the rake task resque:quit scheduler when Rails.env is test' do
49
+ Rails.expects(:env).returns('prod').at_least_once
50
+ ResqueScheduler.expects(:system).with("cd #{Rails.root}; bundle exec cap #{Rails.env} resque:quit_scheduler host=0.0.0.0")
51
+ ResqueScheduler.quit('0.0.0.0')
52
+ end
53
+ end
54
+
55
+ context '.restart' do
56
+ should 'run quit then start' do
57
+ ip = '0.0.0.0'
58
+ ResqueScheduler.expects(:quit).with(ip)
59
+ ResqueScheduler.expects(:start).with(ip)
60
+ ResqueScheduler.restart(ip)
61
+ end
62
+ end
63
+
64
+ context '.farm_status' do
65
+ should 'set the local host status to Stopped' do
66
+ status = ResqueScheduler.farm_status
67
+ assert_equal 'Stopped', status['localhost']
68
+ end
69
+
70
+ should 'set the local host status to running' do
71
+ ResqueScheduler.stubs(:pids).returns('pid')
72
+ status = ResqueScheduler.farm_status
73
+ assert_equal 'Running', status['localhost']
74
+ end
75
+
76
+ should 'set the status to stopped for ip 0.0.0.0 when cap ' do
77
+ ResqueScheduler.expects(:`).returns('')
78
+ Rails.expects(:env).returns('prod').at_least_once
79
+ Resque.expects(:schedule).returns({ job: { 'ip' => '0.0.0.0' } }).at_least_once
80
+ status = ResqueScheduler.farm_status
81
+ assert_equal 'Stopped', status['0.0.0.0']
82
+ end
83
+
84
+ should 'set the status to running for ip 0.0.0.0' do
85
+ ResqueScheduler.expects(:`).returns('resque:scheduler is up')
86
+ Rails.expects(:env).returns('prod').at_least_once
87
+ Resque.expects(:schedule).returns({ job: { 'ip' => '0.0.0.0' } }).at_least_once
88
+ status = ResqueScheduler.farm_status
89
+ assert_equal 'Running', status['0.0.0.0']
90
+ end
91
+ end
92
+
93
+ context '.pids' do
94
+ should 'return an array of pids' do
95
+ pids = <<-eos
96
+ 123
97
+ 1234
98
+ eos
99
+ ResqueScheduler.expects(:`).returns(pids)
100
+ assert_equal %w(123 1234), ResqueScheduler.pids
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,63 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
3
+
4
+ # Testing chained status mixin through SingleRecordLoader
5
+
6
+ class ChainedStatusTest < Test::Unit::TestCase
7
+ context 'Resque::Plugins::ChainedStatus' do
8
+ setup { @uuid = Resque::Plugins::Status::Hash.generate_uuid }
9
+
10
+ context '#included' do
11
+ should 'have Resque::Plugins::Status and InstanceOverrides included' do
12
+ assert_includes SingleRecordLoader.included_modules, Resque::Plugins::ChainedStatus::InstanceOverrides, SingleRecordLoader.included_modules.inspect
13
+ assert_includes SingleRecordLoader.included_modules, Resque::Plugins::Status, SingleRecordLoader.included_modules.inspect
14
+ assert_includes SingleRecordLoader.included_modules, Resque::Plugins::ChainedStatus, SingleRecordLoader.included_modules.inspect
15
+ end
16
+ end
17
+
18
+ context 'InstanceOverrides' do
19
+ setup do
20
+ @worker = Resque::Worker.new(:data_contribution_file)
21
+ @single_record_loader = SingleRecordLoader.new(@uuid, @worker)
22
+ end
23
+
24
+ context '#name' do
25
+ should 'return nil for no status.name' do
26
+ assert_nil @single_record_loader.name
27
+ end
28
+
29
+ should 'return the status name' do
30
+ @single_record_loader.stubs(:status).returns(Resque::Plugins::Status::Hash.new().merge('uuid' => @uuid, 'name' => 'single_record_loader'))
31
+ assert_equal 'single_record_loader', @single_record_loader.name, @single_record_loader.name.inspect
32
+ end
33
+ end
34
+
35
+ context '#completed' do
36
+ should 'add custom messages' do
37
+ response = @single_record_loader.completed(message: 'test', message2: 'testing')
38
+ assert_equal 'test', response.last[:message], response.inspect
39
+ assert_equal 'testing', response.last[:message2], response.inspect
40
+ end
41
+ end
42
+ end
43
+
44
+ context 'ClassOverrides' do
45
+ context '.enqueu_to' do
46
+ should 'raise an ArgumentError for a missing UUID' do
47
+ assert_raises(ArgumentError) { SingleRecordLoader.enqueue_to(:data_contribution_file, 'SingleRecordLoader') }
48
+ end
49
+
50
+ should 'return a uuid and call Resque.enqueue_to' do
51
+ Resque.expects(:enqueue_to).with(:data_contribution_file, 'SingleRecordLoader', @uuid, { 'uuid' => @uuid }).returns(true)
52
+ assert_equal @uuid, SingleRecordLoader.enqueue_to(:data_contribution_file, 'SingleRecordLoader', { 'uuid' => @uuid })
53
+ end
54
+
55
+ should 'return nil' do
56
+ Resque.expects(:enqueue_to).with(:data_contribution_file, 'SingleRecordLoader', @uuid, { 'uuid' => @uuid }).returns(false)
57
+ Resque::Plugins::Status::Hash.expects(:remove).with(@uuid)
58
+ assert_nil SingleRecordLoader.enqueue_to(:data_contribution_file, 'SingleRecordLoader', { 'uuid' => @uuid })
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,193 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
3
+ # Testing resque status mixin through DataContributionFile
4
+
5
+ class StatusTest < Test::Unit::TestCase
6
+ context 'Resque::Plugins::Status' do
7
+ setup do
8
+ Resque.redis.flushdb # flush redis
9
+ @uuid = Resque::Plugins::Status::Hash.generate_uuid
10
+ @worker = Resque::Worker.new(:data_contribution_file)
11
+ end
12
+
13
+ context 'base include' do
14
+ should 'have the attr_reader :workers' do
15
+ data_contribution_file = DataContributionFile.new(@uuid)
16
+ assert_includes data_contribution_file.instance_variable_names, '@worker', data_contribution_file.instance_variable_names.inspect
17
+ end
18
+ end
19
+
20
+ context '#initialize' do
21
+ should 'set the instance variables @uuid, @options, @worker' do
22
+ options = { options: 'option' }
23
+ data_contribution_file = DataContributionFile.new(@uuid, @worker, options)
24
+
25
+ assert_equal options, data_contribution_file.options
26
+ assert_equal @uuid, data_contribution_file.uuid
27
+ assert_equal @worker, data_contribution_file.worker
28
+ end
29
+ end
30
+
31
+ context '.enqueue_to' do
32
+ should 'return a uuid' do
33
+ assert_not_nil DataContributionFile.enqueue_to(:data_contribution_file, 'SingleRecordLoader')
34
+ end
35
+
36
+ should 'return nil' do
37
+ Resque.expects(:enqueue_to).returns(false)
38
+ assert_nil DataContributionFile.enqueue_to(:data_contribution_file, 'SingleRecordLoader')
39
+ end
40
+ end
41
+
42
+ context '.perform' do
43
+ should 'return an instance of DataContributionFile with a UUID' do
44
+ response = DataContributionFile.perform
45
+ assert_kind_of DataContributionFile, response
46
+ assert response.uuid.present?
47
+ end
48
+
49
+ should 'set options, worker and UUID' do
50
+ options = { options: 'Option' }
51
+ response = DataContributionFile.perform(@uuid, options) do
52
+ :single_record_loader
53
+ end
54
+ assert_equal @uuid, response.uuid
55
+ assert_equal options, response.options
56
+ assert_equal :single_record_loader, response.worker
57
+ end
58
+ end
59
+
60
+ context '.counter_key' do
61
+ should 'return a formatted counter key' do
62
+ assert_equal "data_contribution:#{@uuid}", DataContributionFile.counter_key('data_contribution', @uuid)
63
+ end
64
+ end
65
+
66
+ context '.remove' do
67
+ should 'remove from redis' do
68
+ assert_equal 1, DataContributionFile.incr_counter('data_contribution', @uuid)
69
+ DataContributionFile.remove(@uuid)
70
+ assert_equal 0, DataContributionFile.counter('data_contribution', @uuid)
71
+ end
72
+ end
73
+
74
+ context '.counter' do
75
+ should 'return a count of 0' do
76
+ assert_equal 0, DataContributionFile.counter('data_contribution', @uuid)
77
+ end
78
+
79
+ should 'return a count of 1' do
80
+ DataContributionFile.incr_counter('data_contribution', @uuid)
81
+ assert_equal 1, DataContributionFile.counter('data_contribution', @uuid)
82
+ end
83
+ end
84
+
85
+ context '.incr_counter' do
86
+ should 'increment the counter to one' do
87
+ assert_equal 1, DataContributionFile.incr_counter('data_contribution', @uuid)
88
+ end
89
+ end
90
+
91
+ context '#tick' do
92
+ setup do
93
+ @data_contribution = DataContributionFile.new(@uuid, @worker)
94
+ @data_contribution.send(:set_status) # Set the status
95
+ end
96
+
97
+ should 'raise Killed when should_kill? is true' do
98
+ Resque::Plugins::Status::Hash.expects(:should_kill?).returns(true)
99
+ assert_raises(Resque::Plugins::Status::Killed) { @data_contribution.tick }
100
+ end
101
+
102
+ should 'raise Killed when status.killed? is true' do
103
+ # Stub on the hash not the actual status because it will change and wont be stubbed on the right status object
104
+ Resque::Plugins::Status::Hash.expects(:should_kill?).returns(false)
105
+ Resque::Plugins::Status::Hash.any_instance.expects(:killed?).returns(true)
106
+ assert_raises(Resque::Plugins::Status::Killed) { @data_contribution.tick }
107
+ end
108
+
109
+ should 'set status to working' do
110
+ @data_contribution.status.stubs(:completed?).returns(true)
111
+ @data_contribution.worker.expects(:paused?).returns(false).at_least_once # break so we dont hit the sleep for 60 seconds
112
+ @data_contribution.tick
113
+ assert_equal 'working', @data_contribution.status['status'], @data_contribution.status.inspect
114
+ end
115
+ end
116
+
117
+ context '#safe_perform!' do
118
+ setup do
119
+ @data_contribution = DataContributionFile.new(@uuid, @worker)
120
+ @status = Resque::Plugins::Status::Hash.new().merge('uuid' => @uuid)
121
+ @data_contribution.stubs(:status).returns(@status)
122
+ @now = Time.now
123
+ Time.stubs(:now).returns(@now)
124
+ end
125
+
126
+ should 'rescue Killed' do
127
+ # Stub on the hash not the actual status because it will change and wont be stubbed on the right status object
128
+ Resque::Plugins::Status::Hash.expects(:should_kill?).returns(true)
129
+ Rails.logger.expects(:info).with("Job #{@data_contribution} Killed at #{@now}")
130
+ Resque::Plugins::Status::Hash.expects(:killed).with(@uuid)
131
+ assert_nothing_raised(Resque::Plugins::Status::Killed) { @data_contribution.safe_perform! }
132
+ end
133
+
134
+ should 'rescue an exception and call on failure' do
135
+ e = Exception.new('exception')
136
+ Resque::Plugins::Status::Hash.expects(:should_kill?).returns(true)
137
+ @data_contribution.stubs(:kill!).raises(e)
138
+ Rails.logger.expects(:error).with(e)
139
+ @data_contribution.expects(:on_failure).with(e)
140
+ assert_nothing_raised(Exception) { @data_contribution.safe_perform! }
141
+ end
142
+
143
+ should 'rescue an exception and re-raise when the object does not respond to on failure' do
144
+ e = Exception.new('exception')
145
+ Resque::Plugins::Status::Hash.expects(:should_kill?).returns(true)
146
+ @data_contribution.stubs(:kill!).raises(e)
147
+ Rails.logger.expects(:error).with(e)
148
+ @data_contribution.expects(:respond_to?).returns(false)
149
+ assert_raises(Exception) { @data_contribution.safe_perform! }
150
+ end
151
+
152
+ should 'set the status to working then completed when !status.completed?' do
153
+ Resque::Plugins::Status::Hash.expects(:should_kill?).returns(false)
154
+ @status.expects(:failed?).returns(false)
155
+ @status.expects(:completed?).returns(false)
156
+ @data_contribution.expects(:set_status).with({'status' => 'working'})
157
+ @data_contribution.expects(:set_status).with({'status' => 'completed', 'message' => "Completed at #{@now}" })
158
+ @data_contribution.safe_perform!
159
+ end
160
+
161
+ should 'call on_failure when status.failed?' do
162
+ @status.expects(:failed?).returns(true)
163
+ @data_contribution.expects(:on_failure).with(@status.message)
164
+ @data_contribution.safe_perform!
165
+ end
166
+
167
+ should 'call on_success' do
168
+ Resque::Plugins::Status::Hash.expects(:should_kill?).returns(false)
169
+ @status.expects(:failed?).returns(false)
170
+ @status.expects(:completed?).returns(false)
171
+ @data_contribution.expects(:on_success)
172
+ @data_contribution.safe_perform!
173
+ end
174
+ end
175
+
176
+ context '#pause!' do
177
+ should 'set the status to paused' do
178
+ data_contribution = DataContributionFile.new(@uuid, @worker)
179
+ data_contribution.pause!
180
+ assert_equal 'paused', data_contribution.status['status'], data_contribution.status.inspect
181
+ assert_match "#{@worker} paused at", data_contribution.status['message'], data_contribution.status.inspect
182
+ end
183
+ end
184
+
185
+ context '#overview_message=' do
186
+ should 'set the overview_message for the worker' do
187
+ @data_contribution = DataContributionFile.new(@uuid, @worker)
188
+ @data_contribution.overview_message = 'Test'
189
+ assert_equal 'Test', @worker.overview_message, @worker.inspect
190
+ end
191
+ end
192
+ end
193
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Tyll
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2013-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: shoulda
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: shoulda-matchers
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  description:
98
140
  email:
99
141
  - kevintyll@gmail.com
@@ -162,6 +204,8 @@ files:
162
204
  - test/dummy/app/assets/stylesheets/application.css
163
205
  - test/dummy/app/controllers/application_controller.rb
164
206
  - test/dummy/app/helpers/application_helper.rb
207
+ - test/dummy/app/models/data_contribution_file.rb
208
+ - test/dummy/app/models/single_record_loader.rb
165
209
  - test/dummy/app/views/layouts/application.html.erb
166
210
  - test/dummy/config/application.rb
167
211
  - test/dummy/config/boot.rb
@@ -172,13 +216,18 @@ files:
172
216
  - test/dummy/config/initializers/backtrace_silencers.rb
173
217
  - test/dummy/config/initializers/inflections.rb
174
218
  - test/dummy/config/initializers/mime_types.rb
219
+ - test/dummy/config/initializers/resque_manager.rb
175
220
  - test/dummy/config/initializers/secret_token.rb
176
221
  - test/dummy/config/initializers/session_store.rb
177
222
  - test/dummy/config/initializers/wrap_parameters.rb
178
223
  - test/dummy/config/locales/en.yml
224
+ - test/dummy/config/redis.yml
225
+ - test/dummy/config/resque_manager.yml
179
226
  - test/dummy/config/routes.rb
180
227
  - test/dummy/config.ru
228
+ - test/dummy/lib/tasks/resque_setup.rake
181
229
  - test/dummy/log/development.log
230
+ - test/dummy/log/test.log
182
231
  - test/dummy/public/404.html
183
232
  - test/dummy/public/422.html
184
233
  - test/dummy/public/500.html
@@ -215,12 +264,16 @@ files:
215
264
  - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
216
265
  - test/dummy/tmp/cache/assets/E2B/7A0/sprockets%2Fd44ef07be0aa6d5b5dea4d37d7f72b4f
217
266
  - test/functional/resque_manager/resque_controller_test.rb
218
- - test/integration/navigation_test.rb
219
267
  - test/resque_manager_test.rb
220
268
  - test/test_helper.rb
221
269
  - test/unit/helpers/resque_manager/resque_helper_test.rb
270
+ - test/unit/overrides/resque/worker_test.rb
271
+ - test/unit/overrides/resque_scheduler/resque_scheduler_test.rb
272
+ - test/unit/overrides/resque_status/chained_status_test.rb
273
+ - test/unit/overrides/resque_status/status_test.rb
222
274
  homepage: https://github.com/kevintyll/resque_manager
223
- licenses: []
275
+ licenses:
276
+ - MIT
224
277
  metadata: {}
225
278
  post_install_message:
226
279
  rdoc_options: []
@@ -248,6 +301,8 @@ test_files:
248
301
  - test/dummy/app/assets/stylesheets/application.css
249
302
  - test/dummy/app/controllers/application_controller.rb
250
303
  - test/dummy/app/helpers/application_helper.rb
304
+ - test/dummy/app/models/data_contribution_file.rb
305
+ - test/dummy/app/models/single_record_loader.rb
251
306
  - test/dummy/app/views/layouts/application.html.erb
252
307
  - test/dummy/config/application.rb
253
308
  - test/dummy/config/boot.rb
@@ -258,13 +313,18 @@ test_files:
258
313
  - test/dummy/config/initializers/backtrace_silencers.rb
259
314
  - test/dummy/config/initializers/inflections.rb
260
315
  - test/dummy/config/initializers/mime_types.rb
316
+ - test/dummy/config/initializers/resque_manager.rb
261
317
  - test/dummy/config/initializers/secret_token.rb
262
318
  - test/dummy/config/initializers/session_store.rb
263
319
  - test/dummy/config/initializers/wrap_parameters.rb
264
320
  - test/dummy/config/locales/en.yml
321
+ - test/dummy/config/redis.yml
322
+ - test/dummy/config/resque_manager.yml
265
323
  - test/dummy/config/routes.rb
266
324
  - test/dummy/config.ru
325
+ - test/dummy/lib/tasks/resque_setup.rake
267
326
  - test/dummy/log/development.log
327
+ - test/dummy/log/test.log
268
328
  - test/dummy/public/404.html
269
329
  - test/dummy/public/422.html
270
330
  - test/dummy/public/500.html
@@ -301,7 +361,10 @@ test_files:
301
361
  - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
302
362
  - test/dummy/tmp/cache/assets/E2B/7A0/sprockets%2Fd44ef07be0aa6d5b5dea4d37d7f72b4f
303
363
  - test/functional/resque_manager/resque_controller_test.rb
304
- - test/integration/navigation_test.rb
305
364
  - test/resque_manager_test.rb
306
365
  - test/test_helper.rb
307
366
  - test/unit/helpers/resque_manager/resque_helper_test.rb
367
+ - test/unit/overrides/resque/worker_test.rb
368
+ - test/unit/overrides/resque_scheduler/resque_scheduler_test.rb
369
+ - test/unit/overrides/resque_status/chained_status_test.rb
370
+ - test/unit/overrides/resque_status/status_test.rb