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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +12 -12
  3. data/app/controllers/rocket_job_mission_control/application_controller.rb +1 -2
  4. data/app/controllers/rocket_job_mission_control/dirmon_entries_controller.rb +20 -19
  5. data/app/controllers/rocket_job_mission_control/jobs_controller.rb +36 -35
  6. data/app/controllers/rocket_job_mission_control/servers_controller.rb +32 -38
  7. data/app/datatables/rocket_job_mission_control/abstract_datatable.rb +8 -6
  8. data/app/datatables/rocket_job_mission_control/active_workers_datatable.rb +5 -5
  9. data/app/datatables/rocket_job_mission_control/dirmon_entries_datatable.rb +4 -4
  10. data/app/datatables/rocket_job_mission_control/jobs_datatable.rb +55 -62
  11. data/app/datatables/rocket_job_mission_control/servers_datatable.rb +13 -14
  12. data/app/helpers/rocket_job_mission_control/application_helper.rb +42 -41
  13. data/app/helpers/rocket_job_mission_control/jobs_helper.rb +9 -10
  14. data/app/helpers/rocket_job_mission_control/pagination_helper.rb +1 -1
  15. data/app/helpers/rocket_job_mission_control/servers_helper.rb +6 -6
  16. data/app/helpers/rocket_job_mission_control/slices_helper.rb +2 -4
  17. data/app/models/rocket_job_mission_control/access_policy.rb +1 -2
  18. data/app/models/rocket_job_mission_control/authorization.rb +3 -2
  19. data/app/models/rocket_job_mission_control/job_sanitizer.rb +14 -17
  20. data/app/models/rocket_job_mission_control/query.rb +2 -5
  21. data/app/views/rocket_job_mission_control/jobs/_exceptions.html.erb +1 -1
  22. data/app/views/rocket_job_mission_control/jobs/edit_slice.html.erb +1 -1
  23. data/app/views/rocket_job_mission_control/servers/index.html.erb +2 -2
  24. data/config/initializers/assets.rb +5 -7
  25. data/config/locales/en.yml +3 -0
  26. data/config/routes.rb +20 -21
  27. data/lib/rocket_job_mission_control/engine.rb +8 -9
  28. data/lib/rocket_job_mission_control/version.rb +1 -1
  29. data/lib/rocketjob_mission_control.rb +1 -1
  30. data/test/compare_hashes.rb +1 -2
  31. data/test/controllers/rocket_job_mission_control/application_controller_test.rb +13 -13
  32. data/test/controllers/rocket_job_mission_control/dirmon_entries_controller_test.rb +107 -108
  33. data/test/controllers/rocket_job_mission_control/jobs_controller_test.rb +89 -93
  34. data/test/controllers/rocket_job_mission_control/servers_controller_test.rb +66 -103
  35. data/test/helpers/rocket_job_mission_control/application_helper_test.rb +13 -14
  36. data/test/helpers/rocket_job_mission_control/jobs_helper_test.rb +31 -31
  37. data/test/helpers/rocket_job_mission_control/pagination_helper_test.rb +7 -9
  38. data/test/helpers/rocket_job_mission_control/servers_helper_test.rb +15 -15
  39. data/test/helpers/rocket_job_mission_control/slices_helper_test.rb +8 -10
  40. data/test/models/rocket_job_mission_control/job_sanitizer_test.rb +39 -40
  41. data/test/models/rocket_job_mission_control/query_test.rb +26 -28
  42. data/test/test_helper.rb +12 -12
  43. metadata +28 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d59842cf351b7559812f42f2c3650ab55c319011f9a0fd4994c1945741f629ce
4
- data.tar.gz: ddd5ac19c8d8d8c9a7b2b229de298e77719fff27b959776dbaa2e5045e1462e1
3
+ metadata.gz: 82368e0c44c9e3f00c32855cf6b6b74184eb773d5baea76be898d1bff1895561
4
+ data.tar.gz: 488fb8ef02166f06ab899f32972ba0e3e8f1b1ac13a581aa908511706463d35f
5
5
  SHA512:
6
- metadata.gz: 2f41d93ed38b057f3379652a3c05d3f8d57c88b9075ef1b64a706b415cf7200e45a5fc5dbf21833a40e2020d7ef2e3f00ec02a184f56db90fb22ce8dda880354
7
- data.tar.gz: dcc5ab82c17212231557566ccee0c691a23b686d7f94f0980a148882f14c4ad778b3b86b8632ae5f85346ebfa74ab309384dc356a86ce1acfce102c9264c9100
6
+ metadata.gz: f7ce0215da607d10ebc821959f61f28b33a1003b5ab4b44ff346c51abadcf774f39a834920ddd0e1ae22f4eb5f04d5d8b58e2dcc848a770068d733f477027936
7
+ data.tar.gz: c10e28d4b6aed6887f9457ad0f2fcd62b8f4c7db08829db5a6988391201e6ab431fdba1fdbd256d66ea08b1c6035631c89c034a45d86095a889b474622ad9a8f
data/Rakefile CHANGED
@@ -1,36 +1,36 @@
1
1
  # Setup bundler to avoid having to run bundle exec all the time.
2
- require 'rubygems'
3
- require 'bundler/setup'
2
+ require "rubygems"
3
+ require "bundler/setup"
4
4
 
5
- require 'rails/version'
6
- rakefile = Rails.version.to_f >= 5.2 ? '../rjmc/Rakefile' : '../rjmc4/Rakefile'
5
+ require "rails/version"
6
+ rakefile = Rails.version.to_f >= 5.2 ? "../rjmc/Rakefile" : "../rjmc4/Rakefile"
7
7
  APP_RAKEFILE = File.expand_path(rakefile, __FILE__)
8
- load 'rails/tasks/engine.rake'
8
+ load "rails/tasks/engine.rake"
9
9
 
10
- require 'rake/testtask'
11
- require_relative 'lib/rocket_job_mission_control/version'
10
+ require "rake/testtask"
11
+ require_relative "lib/rocket_job_mission_control/version"
12
12
 
13
13
  task :gem do
14
- system 'gem build rocketjob_mission_control.gemspec'
14
+ system "gem build rocketjob_mission_control.gemspec"
15
15
  end
16
16
 
17
17
  task publish: :gem do
18
18
  system "git tag -a v#{RocketJobMissionControl::VERSION} -m 'Tagging #{RocketJobMissionControl::VERSION}'"
19
- system 'git push --tags'
19
+ system "git push --tags"
20
20
  system "gem push rocketjob_mission_control-#{RocketJobMissionControl::VERSION}.gem"
21
21
  system "rm rocketjob_mission_control-#{RocketJobMissionControl::VERSION}.gem"
22
22
  end
23
23
 
24
24
  Rake::TestTask.new(:test) do |t|
25
- t.pattern = 'test/**/*_test.rb'
25
+ t.pattern = "test/**/*_test.rb"
26
26
  t.verbose = true
27
27
  t.warning = false
28
28
  end
29
29
 
30
30
  # By default run tests against all appraisals
31
31
  if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
32
- require 'appraisal'
33
- task default: 'app:appraisal'
32
+ require "appraisal"
33
+ task default: "app:appraisal"
34
34
  else
35
35
  task default: :test
36
36
  end
@@ -7,7 +7,7 @@ module RocketJobMissionControl
7
7
  private
8
8
 
9
9
  def with_time_zone(&block)
10
- if time_zone = session['time_zone'] || 'UTC'
10
+ if time_zone = session["time_zone"] || "UTC"
11
11
  Time.use_zone(time_zone, &block)
12
12
  end
13
13
  end
@@ -30,6 +30,5 @@ module RocketJobMissionControl
30
30
  args[:login]
31
31
  end
32
32
  end
33
-
34
33
  end
35
34
  end
@@ -12,32 +12,33 @@ module RocketJobMissionControl
12
12
 
13
13
  rescue_from AccessGranted::AccessDenied do |exception|
14
14
  raise exception if Rails.env.development? || Rails.env.test?
15
- redirect_to :back, alert: 'Access not authorized.'
15
+
16
+ redirect_to :back, alert: "Access not authorized."
16
17
  end
17
18
 
18
19
  def index
19
- @data_table_url = dirmon_entries_url(format: 'json')
20
- render_datatable(RocketJob::DirmonEntry.all, 'All')
20
+ @data_table_url = dirmon_entries_url(format: "json")
21
+ render_datatable(RocketJob::DirmonEntry.all, "All")
21
22
  end
22
23
 
23
24
  def disabled
24
- @data_table_url = disabled_dirmon_entries_url(format: 'json')
25
- render_datatable(RocketJob::DirmonEntry.disabled, 'Disabled')
25
+ @data_table_url = disabled_dirmon_entries_url(format: "json")
26
+ render_datatable(RocketJob::DirmonEntry.disabled, "Disabled")
26
27
  end
27
28
 
28
29
  def enabled
29
- @data_table_url = enabled_dirmon_entries_url(format: 'json')
30
- render_datatable(RocketJob::DirmonEntry.enabled, 'Enabled')
30
+ @data_table_url = enabled_dirmon_entries_url(format: "json")
31
+ render_datatable(RocketJob::DirmonEntry.enabled, "Enabled")
31
32
  end
32
33
 
33
34
  def failed
34
- @data_table_url = failed_dirmon_entries_url(format: 'json')
35
- render_datatable(RocketJob::DirmonEntry.failed, 'Failed')
35
+ @data_table_url = failed_dirmon_entries_url(format: "json")
36
+ render_datatable(RocketJob::DirmonEntry.failed, "Failed")
36
37
  end
37
38
 
38
39
  def pending
39
- @data_table_url = pending_dirmon_entries_url(format: 'json')
40
- render_datatable(RocketJob::DirmonEntry.pending, 'Pending')
40
+ @data_table_url = pending_dirmon_entries_url(format: "json")
41
+ render_datatable(RocketJob::DirmonEntry.pending, "Pending")
41
42
  end
42
43
 
43
44
  def show
@@ -48,7 +49,7 @@ module RocketJobMissionControl
48
49
  @previous_job_class_names = RocketJob::DirmonEntry.distinct(:job_class_name)
49
50
 
50
51
  if dirmon_params[:job_class_name] && !@dirmon_entry.job_class
51
- @dirmon_entry.errors.add(:job_class_name, 'Invalid Job Class')
52
+ @dirmon_entry.errors.add(:job_class_name, "Invalid Job Class")
52
53
  end
53
54
  end
54
55
 
@@ -94,7 +95,7 @@ module RocketJobMissionControl
94
95
  @dirmon_entry.enable!
95
96
  redirect_to(rocket_job_mission_control.dirmon_entry_path(@dirmon_entry))
96
97
  else
97
- flash[:alert] = t(:failure, scope: [:dirmon_entry, :enable])
98
+ flash[:alert] = t(:failure, scope: %i[dirmon_entry enable])
98
99
  render(:show)
99
100
  end
100
101
  end
@@ -105,7 +106,7 @@ module RocketJobMissionControl
105
106
  @dirmon_entry.disable!
106
107
  redirect_to(rocket_job_mission_control.dirmon_entry_path(@dirmon_entry))
107
108
  else
108
- flash[:alert] = t(:failure, scope: [:dirmon_entry, :disable])
109
+ flash[:alert] = t(:failure, scope: %i[dirmon_entry disable])
109
110
  render(:show)
110
111
  end
111
112
  end
@@ -127,16 +128,16 @@ module RocketJobMissionControl
127
128
 
128
129
  def find_entry_or_redirect
129
130
  unless @dirmon_entry = RocketJob::DirmonEntry.where(id: params[:id]).first
130
- flash[:alert] = t(:failure, scope: [:dirmon_entry, :find], id: params[:id])
131
+ flash[:alert] = t(:failure, scope: %i[dirmon_entry find], id: params[:id])
131
132
 
132
133
  redirect_to(dirmon_entries_path)
133
134
  end
134
135
  end
135
136
 
136
137
  def dirmon_params
137
- params
138
- .fetch(:rocket_job_dirmon_entry, {})
139
- .permit(:name, :archive_directory, :pattern, :job_class_name)
138
+ params.
139
+ fetch(:rocket_job_dirmon_entry, {}).
140
+ permit(:name, :archive_directory, :pattern, :job_class_name)
140
141
  end
141
142
 
142
143
  def render_datatable(entries, description)
@@ -147,7 +148,7 @@ module RocketJobMissionControl
147
148
  end
148
149
  format.json do
149
150
  query = RocketJobMissionControl::Query.new(entries, name: :asc)
150
- query.search_columns = [:job_class_name, :name, :pattern]
151
+ query.search_columns = %i[job_class_name name pattern]
151
152
  query.display_columns = %w[name _type pattern]
152
153
  render(json: DirmonEntriesDatatable.new(view_context, query))
153
154
  end
@@ -14,62 +14,62 @@ module RocketJobMissionControl
14
14
 
15
15
  def index
16
16
  jobs = RocketJob::Job.all.only(JobsDatatable::ALL_FIELDS)
17
- @data_table_url = jobs_url(format: 'json')
17
+ @data_table_url = jobs_url(format: "json")
18
18
 
19
- render_datatable(jobs, 'All', JobsDatatable::ALL_COLUMNS, id: :desc)
19
+ render_datatable(jobs, "All", JobsDatatable::ALL_COLUMNS, id: :desc)
20
20
  end
21
21
 
22
22
  def running
23
23
  # Prevent throttled jobs from displaying.
24
24
  jobs = RocketJob::Job.
25
- running.
26
- where(:started_at.lte => (Time.now - 0.1)).
27
- only(JobsDatatable::RUNNING_FIELDS)
28
- @data_table_url = running_jobs_url(format: 'json')
25
+ running.
26
+ where(:started_at.lte => (Time.now - 0.1)).
27
+ only(JobsDatatable::RUNNING_FIELDS)
28
+ @data_table_url = running_jobs_url(format: "json")
29
29
 
30
- render_datatable(jobs, 'Running', JobsDatatable::RUNNING_COLUMNS, priority: :asc, created_at: :asc)
30
+ render_datatable(jobs, "Running", JobsDatatable::RUNNING_COLUMNS, priority: :asc, created_at: :asc)
31
31
  end
32
32
 
33
33
  def paused
34
34
  jobs = RocketJob::Job.paused.only(JobsDatatable::COMMON_FIELDS)
35
- @data_table_url = paused_jobs_url(format: 'json')
35
+ @data_table_url = paused_jobs_url(format: "json")
36
36
 
37
- render_datatable(jobs, 'Paused', JobsDatatable::PAUSED_COLUMNS, completed_at: :desc)
37
+ render_datatable(jobs, "Paused", JobsDatatable::PAUSED_COLUMNS, completed_at: :desc)
38
38
  end
39
39
 
40
40
  def completed
41
41
  jobs = RocketJob::Job.completed.only(JobsDatatable::COMMON_FIELDS)
42
- @data_table_url = completed_jobs_url(format: 'json')
42
+ @data_table_url = completed_jobs_url(format: "json")
43
43
 
44
- render_datatable(jobs, 'Completed', JobsDatatable::COMPLETED_COLUMNS, completed_at: :desc)
44
+ render_datatable(jobs, "Completed", JobsDatatable::COMPLETED_COLUMNS, completed_at: :desc)
45
45
  end
46
46
 
47
47
  def aborted
48
48
  jobs = RocketJob::Job.aborted.only(JobsDatatable::COMMON_FIELDS)
49
- @data_table_url = aborted_jobs_url(format: 'json')
49
+ @data_table_url = aborted_jobs_url(format: "json")
50
50
 
51
- render_datatable(jobs, 'Aborted', JobsDatatable::ABORTED_COLUMNS, completed_at: :desc)
51
+ render_datatable(jobs, "Aborted", JobsDatatable::ABORTED_COLUMNS, completed_at: :desc)
52
52
  end
53
53
 
54
54
  def failed
55
55
  jobs = RocketJob::Job.failed.only(JobsDatatable::COMMON_FIELDS)
56
- @data_table_url = failed_jobs_url(format: 'json')
56
+ @data_table_url = failed_jobs_url(format: "json")
57
57
 
58
- render_datatable(jobs, 'Failed', JobsDatatable::FAILED_COLUMNS, completed_at: :desc)
58
+ render_datatable(jobs, "Failed", JobsDatatable::FAILED_COLUMNS, completed_at: :desc)
59
59
  end
60
60
 
61
61
  def queued
62
62
  jobs = RocketJob::Job.queued_now.only(JobsDatatable::QUEUED_FIELDS)
63
- @data_table_url = queued_jobs_url(format: 'json')
63
+ @data_table_url = queued_jobs_url(format: "json")
64
64
 
65
- render_datatable(jobs, 'Queued', JobsDatatable::QUEUED_COLUMNS, priority: :asc, created_at: :asc)
65
+ render_datatable(jobs, "Queued", JobsDatatable::QUEUED_COLUMNS, priority: :asc, created_at: :asc)
66
66
  end
67
67
 
68
68
  def scheduled
69
69
  jobs = RocketJob::Job.scheduled.only(JobsDatatable::SCHEDULED_FIELDS)
70
- @data_table_url = scheduled_jobs_url(format: 'json')
70
+ @data_table_url = scheduled_jobs_url(format: "json")
71
71
 
72
- render_datatable(jobs, 'Scheduled', JobsDatatable::SCHEDULED_COLUMNS, run_at: :asc)
72
+ render_datatable(jobs, "Scheduled", JobsDatatable::SCHEDULED_COLUMNS, run_at: :asc)
73
73
  end
74
74
 
75
75
  def update
@@ -138,7 +138,7 @@ module RocketJobMissionControl
138
138
  # Scope: [[slice1], [slice2], [slice(n)]
139
139
  authorize! :view_slice, @job
140
140
  error_type = params[:error_type]
141
- scope = @job.input.failed.where('exception.class_name' => error_type)
141
+ scope = @job.input.failed.where("exception.class_name" => error_type)
142
142
 
143
143
  # Used by pagination to display the correct slice
144
144
  # Offset refers to the slice number from the array "scope".
@@ -149,7 +149,7 @@ module RocketJobMissionControl
149
149
  @lines = current_failure.records
150
150
  @failure_exception = current_failure.try!(:exception)
151
151
  @view_slice_pagination = {
152
- record_number: current_failure['exception']['record_number'],
152
+ record_number: current_failure.processing_record_number,
153
153
  offset: @offset,
154
154
  total: (scope.count - 1)
155
155
  }
@@ -162,7 +162,7 @@ module RocketJobMissionControl
162
162
  error_type = params[:error_type]
163
163
  @line_index = params[:line_index].to_i
164
164
  @offset = params.fetch(:offset, 0).to_i
165
- scope = @job.input.failed.where('exception.class_name' => error_type)
165
+ scope = @job.input.failed.where("exception.class_name" => error_type)
166
166
  current_failure = scope.order(_id: 1).limit(1).skip(@offset).first
167
167
  @lines = current_failure.records
168
168
  @failure_exception = current_failure.try!(:exception)
@@ -174,20 +174,20 @@ module RocketJobMissionControl
174
174
  # Params from the edit_slice form
175
175
  error_type = params[:error_type]
176
176
  offset = params[:offset]
177
- updated_records = params['job']['records']
177
+ updated_records = params["job"]["records"]
178
178
 
179
179
  # Finds specific slice [Array]
180
- slice = @job.input.failed.skip(offset).first
180
+ slice = @job.input.failed.skip(offset).first
181
181
 
182
182
  # Assings modified slice (from the form) back to slice
183
183
  slice.records = updated_records
184
184
 
185
185
  if slice.save
186
186
  logger.info("Slice Updated By #{login}, job: #{@job.id}, file_name: #{@job.upload_file_name}")
187
- flash[:success] = 'slice updated'
187
+ flash[:success] = "slice updated"
188
188
  redirect_to view_slice_job_path(@job, error_type: error_type)
189
189
  else
190
- flash[:danger] = 'Error updating slice.'
190
+ flash[:danger] = "Error updating slice."
191
191
  end
192
192
  end
193
193
 
@@ -200,7 +200,7 @@ module RocketJobMissionControl
200
200
  line_index = params[:line_index].to_i
201
201
 
202
202
  # Finds specific slice [Array]
203
- scope = @job.input.failed.where('exception.class_name' => error_type)
203
+ scope = @job.input.failed.where("exception.class_name" => error_type)
204
204
  slice = scope.order(_id: 1).limit(1).skip(offset).first
205
205
 
206
206
  # Finds and deletes line
@@ -213,9 +213,9 @@ module RocketJobMissionControl
213
213
  if slice.save
214
214
  logger.info("Line Deleted By #{login}, job: #{@job.id}, file_name: #{@job.upload_file_name}")
215
215
  redirect_to view_slice_job_path(@job, error_type: error_type)
216
- flash[:success] = 'line removed'
216
+ flash[:success] = "line removed"
217
217
  else
218
- flash[:danger] = 'Error removing line.'
218
+ flash[:danger] = "Error removing line."
219
219
  end
220
220
  end
221
221
 
@@ -229,9 +229,9 @@ module RocketJobMissionControl
229
229
  redirect_to(job_path(@job))
230
230
  end
231
231
 
232
- scope = @job.input.failed.where('exception.class_name' => error_type)
232
+ scope = @job.input.failed.where("exception.class_name" => error_type)
233
233
  count = scope.count
234
- unless count > 0
234
+ unless count.positive?
235
235
  flash[:notice] = t(:no_errors, scope: %i[job failures])
236
236
  redirect_to(job_path(@job))
237
237
  end
@@ -269,18 +269,19 @@ module RocketJobMissionControl
269
269
 
270
270
  def error_occurred(exception)
271
271
  if defined?(SemanticLogger::Logger) && logger.is_a?(SemanticLogger::Logger)
272
- logger.error 'Error loading a job', exception
272
+ logger.error "Error loading a job", exception
273
273
  else
274
274
  logger.error "Error loading a job. #{exception.class}: #{exception.message}\n#{(exception.backtrace || []).join("\n")}"
275
275
  end
276
276
 
277
277
  flash[:danger] = if exception.is_a?(AccessGranted::AccessDenied)
278
- 'Access not authorized.'
278
+ "Access not authorized."
279
279
  else
280
- 'Error loading jobs.'
280
+ "Error loading jobs."
281
281
  end
282
282
 
283
283
  raise exception if Rails.env.development? || Rails.env.test?
284
+
284
285
  redirect_to :back
285
286
  end
286
287
 
@@ -307,7 +308,7 @@ module RocketJobMissionControl
307
308
  h = {data: index.to_s}
308
309
  h[:width] = column[:width] if column.key?(:width)
309
310
  h[:orderable] = column[:orderable] if column.key?(:orderable)
310
- index += 1
311
+ index += 1
311
312
  h
312
313
  end
313
314
  end
@@ -12,56 +12,59 @@ module RocketJobMissionControl
12
12
 
13
13
  rescue_from AccessGranted::AccessDenied do |exception|
14
14
  raise exception if Rails.env.development? || Rails.env.test?
15
- redirect_to :back, alert: 'Access not authorized.'
15
+
16
+ redirect_to :back, alert: "Access not authorized."
16
17
  end
17
18
 
18
19
  def index
19
- @data_table_url = servers_url(format: 'json')
20
- @actions = [:pause, :resume, :stop, :kill, :destroy_zombies]
21
- render_datatable(RocketJob::Server.all, 'All')
20
+ @data_table_url = servers_url(format: "json")
21
+ @actions = %i[pause resume stop kill destroy_zombies]
22
+ render_datatable(RocketJob::Server.all, "All")
22
23
  end
23
24
 
24
25
  def starting
25
- @data_table_url = starting_servers_url(format: 'json')
26
- @actions = [:pause, :stop, :kill]
27
- render_datatable(RocketJob::Server.starting, 'Starting')
26
+ @data_table_url = starting_servers_url(format: "json")
27
+ @actions = %i[pause stop kill]
28
+ render_datatable(RocketJob::Server.starting, "Starting")
28
29
  end
29
30
 
30
31
  def running
31
- @data_table_url = running_servers_url(format: 'json')
32
- @actions = [:pause, :stop, :kill, :destroy_zombies]
33
- render_datatable(RocketJob::Server.running, 'Running')
32
+ @data_table_url = running_servers_url(format: "json")
33
+ @actions = %i[pause stop kill destroy_zombies]
34
+ render_datatable(RocketJob::Server.running, "Running")
34
35
  end
35
36
 
36
37
  def paused
37
- @data_table_url = paused_servers_url(format: 'json')
38
- @actions = [:resume, :destroy_zombies]
39
- render_datatable(RocketJob::Server.paused, 'Paused')
38
+ @data_table_url = paused_servers_url(format: "json")
39
+ @actions = %i[resume destroy_zombies]
40
+ render_datatable(RocketJob::Server.paused, "Paused")
40
41
  end
41
42
 
42
43
  def stopping
43
- @data_table_url = stopping_servers_url(format: 'json')
44
+ @data_table_url = stopping_servers_url(format: "json")
44
45
  @actions = [:destroy_zombies]
45
- render_datatable(RocketJob::Server.stopping, 'Stopping')
46
+ render_datatable(RocketJob::Server.stopping, "Stopping")
46
47
  end
47
48
 
48
49
  def zombie
49
- @data_table_url = zombie_servers_url(format: 'json')
50
+ @data_table_url = zombie_servers_url(format: "json")
50
51
  @actions = [:destroy_zombies]
51
- render_datatable(RocketJob::Server.zombies, 'Zombie')
52
+ render_datatable(RocketJob::Server.zombies, "Zombie")
52
53
  end
53
54
 
54
- VALID_ACTIONS = [:stop, :kill, :pause, :resume, :thread_dump]
55
+ VALID_ACTIONS = %i[stop kill pause resume thread_dump].freeze
55
56
 
56
57
  def update_all
57
- authorize! :update_all, RocketJob::Server
58
58
  server_action = params[:server_action].to_sym
59
+ authorize! server_action, RocketJob::Server
60
+
59
61
  if server_action == :destroy_zombies
60
62
  RocketJob::Server.destroy_zombies
61
63
  elsif VALID_ACTIONS.include?(server_action)
62
64
  RocketJob::Subscribers::Server.publish(server_action)
65
+ flash[:notice] = t(:success, scope: %i[server update_all], action: server_action.to_s)
63
66
  else
64
- flash[:alert] = t(:invalid, scope: [:server, :update_all])
67
+ flash[:alert] = t(:invalid, scope: %i[server update_all])
65
68
  end
66
69
 
67
70
  # TODO: Refresh the same page it was on
@@ -72,11 +75,8 @@ module RocketJobMissionControl
72
75
 
73
76
  def stop
74
77
  authorize! :stop, @server
75
- if @server.may_stop?
76
- @server.stop!
77
- else
78
- flash[:alert] = t(:failure, scope: [:server, :stop])
79
- end
78
+ RocketJob::Subscribers::Server.publish(:stop, server_id: @server.id)
79
+ flash[:notice] = t(:success, scope: %i[server update_one], action: "stop", name: @server.name)
80
80
 
81
81
  respond_to do |format|
82
82
  format.html { redirect_to servers_path }
@@ -86,7 +86,7 @@ module RocketJobMissionControl
86
86
  def destroy
87
87
  authorize! :destroy, @server
88
88
  @server.destroy
89
- flash[:notice] = t(:success, scope: [:server, :destroy])
89
+ flash[:notice] = t(:success, scope: %i[server destroy])
90
90
 
91
91
  respond_to do |format|
92
92
  format.html { redirect_to servers_path }
@@ -95,11 +95,8 @@ module RocketJobMissionControl
95
95
 
96
96
  def pause
97
97
  authorize! :pause, @server
98
- if @server.may_pause?
99
- @server.pause!
100
- else
101
- flash[:alert] = t(:failure, scope: [:server, :pause])
102
- end
98
+ RocketJob::Subscribers::Server.publish(:pause, server_id: @server.id)
99
+ flash[:notice] = t(:success, scope: %i[server update_one], action: "pause", name: @server.name)
103
100
 
104
101
  respond_to do |format|
105
102
  format.html { redirect_to servers_path }
@@ -108,11 +105,8 @@ module RocketJobMissionControl
108
105
 
109
106
  def resume
110
107
  authorize! :resume, @server
111
- if @server.may_resume?
112
- @server.resume!
113
- else
114
- flash[:alert] = t(:failure, scope: [:server, :resume])
115
- end
108
+ RocketJob::Subscribers::Server.publish(:resume, server_id: @server.id)
109
+ flash[:notice] = t(:success, scope: %i[server update_one], action: "resume", name: @server.name)
116
110
 
117
111
  respond_to do |format|
118
112
  format.html { redirect_to servers_path }
@@ -130,7 +124,7 @@ module RocketJobMissionControl
130
124
  format.html do
131
125
  @description = description
132
126
  @states = RocketJob::Server.aasm.states.map { |s| s.name.to_s }
133
- @states << 'zombie'
127
+ @states << "zombie"
134
128
 
135
129
  @server_counts = RocketJob::Server.counts_by_state
136
130
  # TODO: Move into RocketJob
@@ -146,7 +140,7 @@ module RocketJobMissionControl
146
140
 
147
141
  def find_server_or_redirect
148
142
  unless @server = RocketJob::Server.where(id: params[:id]).first
149
- flash[:alert] = t(:failure, scope: [:server, :find], id: params[:id])
143
+ flash[:alert] = t(:failure, scope: %i[server find], id: params[:id])
150
144
 
151
145
  redirect_to(servers_path)
152
146
  end