rocketjob_mission_control 4.3.0 → 5.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -12
- data/app/controllers/rocket_job_mission_control/application_controller.rb +1 -2
- data/app/controllers/rocket_job_mission_control/dirmon_entries_controller.rb +20 -19
- data/app/controllers/rocket_job_mission_control/jobs_controller.rb +36 -35
- data/app/controllers/rocket_job_mission_control/servers_controller.rb +32 -38
- data/app/datatables/rocket_job_mission_control/abstract_datatable.rb +8 -6
- data/app/datatables/rocket_job_mission_control/active_workers_datatable.rb +5 -5
- data/app/datatables/rocket_job_mission_control/dirmon_entries_datatable.rb +4 -4
- data/app/datatables/rocket_job_mission_control/jobs_datatable.rb +55 -62
- data/app/datatables/rocket_job_mission_control/servers_datatable.rb +13 -14
- data/app/helpers/rocket_job_mission_control/application_helper.rb +42 -41
- data/app/helpers/rocket_job_mission_control/jobs_helper.rb +9 -10
- data/app/helpers/rocket_job_mission_control/pagination_helper.rb +1 -1
- data/app/helpers/rocket_job_mission_control/servers_helper.rb +6 -6
- data/app/helpers/rocket_job_mission_control/slices_helper.rb +2 -4
- data/app/models/rocket_job_mission_control/access_policy.rb +1 -2
- data/app/models/rocket_job_mission_control/authorization.rb +3 -2
- data/app/models/rocket_job_mission_control/job_sanitizer.rb +14 -17
- data/app/models/rocket_job_mission_control/query.rb +2 -5
- data/app/views/rocket_job_mission_control/jobs/_exceptions.html.erb +1 -1
- data/app/views/rocket_job_mission_control/jobs/edit_slice.html.erb +1 -1
- data/app/views/rocket_job_mission_control/servers/index.html.erb +2 -2
- data/config/initializers/assets.rb +5 -7
- data/config/locales/en.yml +3 -0
- data/config/routes.rb +20 -21
- data/lib/rocket_job_mission_control/engine.rb +8 -9
- data/lib/rocket_job_mission_control/version.rb +1 -1
- data/lib/rocketjob_mission_control.rb +1 -1
- data/test/compare_hashes.rb +1 -2
- data/test/controllers/rocket_job_mission_control/application_controller_test.rb +13 -13
- data/test/controllers/rocket_job_mission_control/dirmon_entries_controller_test.rb +107 -108
- data/test/controllers/rocket_job_mission_control/jobs_controller_test.rb +89 -93
- data/test/controllers/rocket_job_mission_control/servers_controller_test.rb +66 -103
- data/test/helpers/rocket_job_mission_control/application_helper_test.rb +13 -14
- data/test/helpers/rocket_job_mission_control/jobs_helper_test.rb +31 -31
- data/test/helpers/rocket_job_mission_control/pagination_helper_test.rb +7 -9
- data/test/helpers/rocket_job_mission_control/servers_helper_test.rb +15 -15
- data/test/helpers/rocket_job_mission_control/slices_helper_test.rb +8 -10
- data/test/models/rocket_job_mission_control/job_sanitizer_test.rb +39 -40
- data/test/models/rocket_job_mission_control/query_test.rb +26 -28
- data/test/test_helper.rb +12 -12
- metadata +28 -28
@@ -1,9 +1,8 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
require_relative "../../compare_hashes"
|
3
3
|
|
4
4
|
module RocketJobMissionControl
|
5
5
|
class JobsControllerTest < ActionController::TestCase
|
6
|
-
|
7
6
|
class PausableJob < RocketJob::Job
|
8
7
|
self.pausable = true
|
9
8
|
|
@@ -29,9 +28,9 @@ module RocketJobMissionControl
|
|
29
28
|
let :failed_job do
|
30
29
|
job = KaboomBatchJob.new(slice_size: 1)
|
31
30
|
job.upload do |stream|
|
32
|
-
stream <<
|
33
|
-
stream <<
|
34
|
-
stream <<
|
31
|
+
stream << "first record"
|
32
|
+
stream << "second record"
|
33
|
+
stream << "third record"
|
35
34
|
end
|
36
35
|
job.save!
|
37
36
|
|
@@ -49,29 +48,29 @@ module RocketJobMissionControl
|
|
49
48
|
|
50
49
|
let :one_job_for_every_state do
|
51
50
|
job_states.collect do |state|
|
52
|
-
RocketJob::Jobs::SimpleJob.create!(state: state, worker_name:
|
51
|
+
RocketJob::Jobs::SimpleJob.create!(state: state, worker_name: "worker", started_at: (Time.now - 0.5))
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
[
|
55
|
+
%i[pause resume abort retry fail].each do |state|
|
57
56
|
describe "PATCH ##{state}" do
|
58
|
-
describe
|
57
|
+
describe "with an invalid job id" do
|
59
58
|
before do
|
60
59
|
params = {id: 42, job: {id: 42, priority: 12}}
|
61
60
|
params = {params: params} if Rails.version.to_i >= 5
|
62
61
|
patch state, params
|
63
62
|
end
|
64
63
|
|
65
|
-
it
|
64
|
+
it "redirects" do
|
66
65
|
assert_redirected_to jobs_path
|
67
66
|
end
|
68
67
|
|
69
|
-
it
|
70
|
-
assert_equal I18n.t(:failure, scope: [
|
68
|
+
it "adds a flash alert message" do
|
69
|
+
assert_equal I18n.t(:failure, scope: %i[job find], id: 42), flash[:alert]
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
74
|
-
describe
|
73
|
+
describe "with a valid job id" do
|
75
74
|
before do
|
76
75
|
case state
|
77
76
|
when :pause, :fail, :abort
|
@@ -86,18 +85,18 @@ module RocketJobMissionControl
|
|
86
85
|
patch state, params
|
87
86
|
end
|
88
87
|
|
89
|
-
it
|
88
|
+
it "redirects to the job" do
|
90
89
|
assert_redirected_to job_path(pausable_job.id)
|
91
90
|
end
|
92
91
|
|
93
|
-
it
|
92
|
+
it "transitions the job" do
|
94
93
|
refute_equal state, pausable_job.state
|
95
94
|
end
|
96
95
|
end
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
|
-
describe
|
99
|
+
describe "PATCH #run_now" do
|
101
100
|
let(:scheduled_job) { RocketJob::Jobs::SimpleJob.create!(run_at: 2.days.from_now) }
|
102
101
|
|
103
102
|
before do
|
@@ -106,45 +105,44 @@ module RocketJobMissionControl
|
|
106
105
|
patch :run_now, params
|
107
106
|
end
|
108
107
|
|
109
|
-
it
|
108
|
+
it "redirects to the job path" do
|
110
109
|
assert_redirected_to job_path(scheduled_job.id)
|
111
110
|
end
|
112
111
|
|
113
|
-
it
|
112
|
+
it "updates run_at" do
|
114
113
|
assert_nil scheduled_job.reload.run_at
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
118
|
-
|
119
117
|
describe "PATCH #update" do
|
120
|
-
describe
|
118
|
+
describe "with an invalid job id" do
|
121
119
|
before do
|
122
120
|
params = {id: 42, job: {id: 42, priority: 12}}
|
123
121
|
params = {params: params} if Rails.version.to_i >= 5
|
124
122
|
patch :update, params
|
125
123
|
end
|
126
124
|
|
127
|
-
it
|
125
|
+
it "redirects" do
|
128
126
|
assert_redirected_to jobs_path
|
129
127
|
end
|
130
128
|
|
131
|
-
it
|
132
|
-
assert_equal I18n.t(:failure, scope: [
|
129
|
+
it "adds a flash alert message" do
|
130
|
+
assert_equal I18n.t(:failure, scope: %i[job find], id: 42), flash[:alert]
|
133
131
|
end
|
134
132
|
end
|
135
133
|
|
136
134
|
describe "with a valid job id" do
|
137
135
|
before do
|
138
|
-
params = {id: job.id, job: {id: job.id, priority: 12, blah: 23, description:
|
136
|
+
params = {id: job.id, job: {id: job.id, priority: 12, blah: 23, description: "", log_level: "", state: "failed"}}
|
139
137
|
params = {params: params} if Rails.version.to_i >= 5
|
140
138
|
patch :update, params
|
141
139
|
end
|
142
140
|
|
143
|
-
it
|
141
|
+
it "redirects to the job" do
|
144
142
|
assert_redirected_to job_path(job.id)
|
145
143
|
end
|
146
144
|
|
147
|
-
it
|
145
|
+
it "updates the job correctly" do
|
148
146
|
assert_equal 12, job.reload.priority
|
149
147
|
end
|
150
148
|
|
@@ -157,20 +155,20 @@ module RocketJobMissionControl
|
|
157
155
|
end
|
158
156
|
end
|
159
157
|
|
160
|
-
describe
|
161
|
-
describe
|
158
|
+
describe "GET #show" do
|
159
|
+
describe "with an invalid job id" do
|
162
160
|
before do
|
163
161
|
params = {id: 42}
|
164
162
|
params = {params: params} if Rails.version.to_i >= 5
|
165
163
|
get :show, params
|
166
164
|
end
|
167
165
|
|
168
|
-
it
|
166
|
+
it "redirects" do
|
169
167
|
assert_redirected_to jobs_path
|
170
168
|
end
|
171
169
|
|
172
|
-
it
|
173
|
-
assert_equal I18n.t(:failure, scope: [
|
170
|
+
it "adds a flash alert message" do
|
171
|
+
assert_equal I18n.t(:failure, scope: %i[job find], id: 42), flash[:alert]
|
174
172
|
end
|
175
173
|
end
|
176
174
|
|
@@ -181,73 +179,73 @@ module RocketJobMissionControl
|
|
181
179
|
get :show, params
|
182
180
|
end
|
183
181
|
|
184
|
-
it
|
182
|
+
it "succeeds" do
|
185
183
|
assert_response :success
|
186
184
|
end
|
187
185
|
|
188
|
-
it
|
186
|
+
it "assigns the job" do
|
189
187
|
assert_equal job.id, assigns(:job).id
|
190
188
|
end
|
191
189
|
end
|
192
190
|
end
|
193
191
|
|
194
|
-
describe
|
195
|
-
describe
|
192
|
+
describe "GET #exception" do
|
193
|
+
describe "with an invalid job id" do
|
196
194
|
before do
|
197
195
|
params = {id: 42}
|
198
196
|
params = {params: params} if Rails.version.to_i >= 5
|
199
197
|
get :exception, params
|
200
198
|
end
|
201
199
|
|
202
|
-
it
|
200
|
+
it "redirects" do
|
203
201
|
assert_redirected_to jobs_path
|
204
202
|
end
|
205
203
|
|
206
|
-
it
|
207
|
-
assert_equal I18n.t(:failure, scope: [
|
204
|
+
it "adds a flash alert message" do
|
205
|
+
assert_equal I18n.t(:failure, scope: %i[job find], id: 42), flash[:alert]
|
208
206
|
end
|
209
207
|
end
|
210
208
|
|
211
|
-
describe
|
212
|
-
describe
|
209
|
+
describe "with a valid job id" do
|
210
|
+
describe "without an exception" do
|
213
211
|
before do
|
214
|
-
params = {id: failed_job.id, error_type:
|
212
|
+
params = {id: failed_job.id, error_type: "Blah"}
|
215
213
|
params = {params: params} if Rails.version.to_i >= 5
|
216
214
|
get :exception, params
|
217
215
|
end
|
218
216
|
|
219
|
-
it
|
217
|
+
it "redirects to job path" do
|
220
218
|
assert_redirected_to job_path(failed_job.id)
|
221
219
|
end
|
222
220
|
|
223
|
-
it
|
224
|
-
assert_equal I18n.t(:no_errors, scope: [
|
221
|
+
it "notifies the user" do
|
222
|
+
assert_equal I18n.t(:no_errors, scope: %i[job failures]), flash[:notice]
|
225
223
|
end
|
226
224
|
end
|
227
225
|
|
228
|
-
describe
|
226
|
+
describe "with exception" do
|
229
227
|
before do
|
230
|
-
params = {id: failed_job.id, error_type:
|
228
|
+
params = {id: failed_job.id, error_type: "ArgumentError"}
|
231
229
|
params = {params: params} if Rails.version.to_i >= 5
|
232
230
|
get :exception, params
|
233
231
|
end
|
234
232
|
|
235
|
-
it
|
233
|
+
it "succeeds" do
|
236
234
|
assert_response :success
|
237
235
|
end
|
238
236
|
|
239
|
-
it
|
237
|
+
it "assigns the job" do
|
240
238
|
assert_equal failed_job.id, assigns(:job).id
|
241
239
|
end
|
242
240
|
|
243
|
-
it
|
241
|
+
it "paginates" do
|
244
242
|
assert_equal 0, assigns(:pagination)[:offset], assigns(:pagination)
|
245
243
|
assert_equal 1, assigns(:pagination)[:total], assigns(:pagination)
|
246
244
|
end
|
247
245
|
|
248
|
-
it
|
249
|
-
assert_equal
|
250
|
-
assert_equal
|
246
|
+
it "returns the first exception" do
|
247
|
+
assert_equal "ArgumentError", assigns(:failure_exception).class_name
|
248
|
+
assert_equal "Blowing up on record: 1", assigns(:failure_exception).message
|
251
249
|
assert assigns(:failure_exception).backtrace.present?
|
252
250
|
end
|
253
251
|
end
|
@@ -256,17 +254,17 @@ module RocketJobMissionControl
|
|
256
254
|
|
257
255
|
([:index] + job_states).each do |state|
|
258
256
|
describe "GET ##{state}" do
|
259
|
-
describe
|
257
|
+
describe "html" do
|
260
258
|
describe "with no #{state} servers" do
|
261
259
|
before do
|
262
260
|
get state
|
263
261
|
end
|
264
262
|
|
265
|
-
it
|
263
|
+
it "succeeds" do
|
266
264
|
assert_response :success
|
267
265
|
end
|
268
266
|
|
269
|
-
it
|
267
|
+
it "renders template" do
|
270
268
|
assert_template :index
|
271
269
|
end
|
272
270
|
end
|
@@ -277,23 +275,23 @@ module RocketJobMissionControl
|
|
277
275
|
get state
|
278
276
|
end
|
279
277
|
|
280
|
-
it
|
278
|
+
it "succeeds" do
|
281
279
|
assert_response :success
|
282
280
|
end
|
283
281
|
|
284
|
-
it
|
282
|
+
it "renders template" do
|
285
283
|
assert_template :index
|
286
284
|
end
|
287
285
|
end
|
288
286
|
end
|
289
287
|
|
290
|
-
describe
|
288
|
+
describe "json" do
|
291
289
|
describe "with no #{state} server" do
|
292
290
|
before do
|
293
291
|
get state, format: :json
|
294
292
|
end
|
295
293
|
|
296
|
-
it
|
294
|
+
it "succeeds" do
|
297
295
|
assert_response :success
|
298
296
|
json = JSON.parse(response.body)
|
299
297
|
expected = {
|
@@ -313,81 +311,79 @@ module RocketJobMissionControl
|
|
313
311
|
get state, format: :json
|
314
312
|
end
|
315
313
|
|
316
|
-
it
|
314
|
+
it "succeeds" do
|
317
315
|
assert_response :success
|
318
316
|
json = JSON.parse(response.body)
|
319
317
|
expected_data = {
|
320
318
|
aborted: {
|
321
319
|
"0" => /#{RocketJob::Jobs::SimpleJob.name}/,
|
322
|
-
"1" =>
|
320
|
+
"1" => "",
|
323
321
|
"2" => /UTC/,
|
324
322
|
"3" => /ms/,
|
325
|
-
"4" =>
|
323
|
+
"4" => %r{/jobs/#{RocketJob::Jobs::SimpleJob.aborted.first.id}},
|
326
324
|
"DT_RowClass" => "card callout callout-aborted"
|
327
325
|
},
|
328
326
|
failed: {
|
329
327
|
"0" => /#{RocketJob::Jobs::SimpleJob.name}/,
|
330
|
-
"1" =>
|
328
|
+
"1" => "",
|
331
329
|
"2" => /UTC/,
|
332
330
|
"3" => /ms/,
|
333
|
-
"4" =>
|
331
|
+
"4" => %r{/jobs/#{RocketJob::Jobs::SimpleJob.failed.first.id}},
|
334
332
|
"DT_RowClass" => "card callout callout-failed"
|
335
333
|
},
|
336
334
|
paused: {
|
337
335
|
"0" => /#{RocketJob::Jobs::SimpleJob.name}/,
|
338
|
-
"1" =>
|
336
|
+
"1" => "",
|
339
337
|
"2" => /UTC/,
|
340
338
|
"3" => /ms/,
|
341
|
-
"4" =>
|
339
|
+
"4" => %r{/jobs/#{RocketJob::Jobs::SimpleJob.paused.first.id}},
|
342
340
|
"DT_RowClass" => "card callout callout-paused"
|
343
341
|
},
|
344
342
|
completed: {
|
345
343
|
"0" => /#{RocketJob::Jobs::SimpleJob.name}/,
|
346
|
-
"1" =>
|
344
|
+
"1" => "",
|
347
345
|
"2" => /UTC/,
|
348
346
|
"3" => /ms/,
|
349
|
-
"4" =>
|
347
|
+
"4" => %r{/jobs/#{RocketJob::Jobs::SimpleJob.completed.first.id}},
|
350
348
|
"DT_RowClass" => "card callout callout-completed"
|
351
349
|
},
|
352
350
|
running: {
|
353
351
|
"0" => /#{RocketJob::Jobs::SimpleJob.name}/,
|
354
|
-
"1" =>
|
352
|
+
"1" => "",
|
355
353
|
"2" => /UTC/,
|
356
354
|
"3" => /ms/,
|
357
|
-
"4" =>
|
355
|
+
"4" => %r{/jobs/#{RocketJob::Jobs::SimpleJob.running.first.id}},
|
358
356
|
"DT_RowClass" => "card callout callout-running"
|
359
357
|
},
|
360
358
|
queued: {
|
361
359
|
"0" => /#{RocketJob::Jobs::SimpleJob.name}/,
|
362
|
-
"1" =>
|
363
|
-
"2" => /
|
360
|
+
"1" => "",
|
361
|
+
"2" => /0/,
|
364
362
|
"3" => /ms/,
|
365
|
-
"4" =>
|
363
|
+
"4" => %r{/jobs/#{RocketJob::Jobs::SimpleJob.queued.first.id}},
|
366
364
|
"DT_RowClass" => "card callout callout-queued"
|
367
|
-
}
|
365
|
+
}
|
368
366
|
}
|
369
367
|
|
370
368
|
if state == :index
|
371
|
-
assert_equal 0, json[
|
372
|
-
assert_equal 6, json[
|
373
|
-
assert_equal 6, json[
|
374
|
-
compare_array_of_hashes
|
369
|
+
assert_equal 0, json["draw"]
|
370
|
+
assert_equal 6, json["recordsTotal"]
|
371
|
+
assert_equal 6, json["recordsFiltered"]
|
372
|
+
compare_array_of_hashes(expected_data.values, json["data"])
|
375
373
|
else
|
376
|
-
assert_equal 0, json[
|
377
|
-
assert_equal 1, json[
|
378
|
-
assert_equal 1, json[
|
374
|
+
assert_equal 0, json["draw"]
|
375
|
+
assert_equal 1, json["recordsTotal"]
|
376
|
+
assert_equal 1, json["recordsFiltered"]
|
379
377
|
# Columns change by state
|
380
|
-
#compare_hash expected_data[state], json['data'].first
|
378
|
+
# compare_hash expected_data[state], json['data'].first
|
381
379
|
end
|
382
380
|
end
|
383
381
|
end
|
384
|
-
|
385
382
|
end
|
386
|
-
|
387
383
|
end
|
388
384
|
end
|
389
385
|
|
390
|
-
describe
|
386
|
+
describe "role base authentication control" do
|
391
387
|
%i[index aborted completed failed paused queued running scheduled].each do |method|
|
392
388
|
it "#{method} has read access as default" do
|
393
389
|
get method, format: :json
|
@@ -396,7 +392,7 @@ module RocketJobMissionControl
|
|
396
392
|
end
|
397
393
|
|
398
394
|
%i[update abort retry pause resume run_now fail].each do |method|
|
399
|
-
describe
|
395
|
+
describe method.to_s do
|
400
396
|
before do
|
401
397
|
case method
|
402
398
|
when :pause, :fail, :abort
|
@@ -431,7 +427,7 @@ module RocketJobMissionControl
|
|
431
427
|
end
|
432
428
|
end
|
433
429
|
|
434
|
-
[
|
430
|
+
%i[view_slice edit_slice].each do |method|
|
435
431
|
describe "with a failed slice" do
|
436
432
|
it "access ##{method}" do
|
437
433
|
params = {:error_type => "ArgumentError", "record_number" => "9", "id" => failed_job.id}
|
@@ -444,25 +440,25 @@ module RocketJobMissionControl
|
|
444
440
|
|
445
441
|
describe "#update slice" do
|
446
442
|
before do
|
447
|
-
params = {
|
443
|
+
params = {"job" => {"records" => %w[1 2 3]}, "error_type" => "CSV::MalformedCSVError", "offset" => "1", "id" => failed_job.id.to_s}
|
448
444
|
params = {params: params} if Rails.version.to_i >= 5
|
449
445
|
post :update_slice, params
|
450
446
|
end
|
451
447
|
|
452
|
-
it
|
448
|
+
it "redirects" do
|
453
449
|
assert_redirected_to view_slice_job_path(failed_job, error_type: "CSV::MalformedCSVError")
|
454
450
|
end
|
455
451
|
|
456
|
-
it
|
457
|
-
assert_equal
|
452
|
+
it "adds a flash success message" do
|
453
|
+
assert_equal "slice updated", flash[:success]
|
458
454
|
end
|
459
455
|
end
|
460
456
|
end
|
461
457
|
|
462
458
|
def set_role(r)
|
463
|
-
Config.authorization_callback =
|
459
|
+
Config.authorization_callback = lambda {
|
464
460
|
{roles: [r]}
|
465
|
-
|
461
|
+
}
|
466
462
|
end
|
467
463
|
end
|
468
464
|
end
|