rocketjob_mission_control 3.0.0.rc1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +10 -6
  3. data/app/assets/javascripts/rocket_job_mission_control/application.js +4 -3
  4. data/app/assets/javascripts/rocket_job_mission_control/base.js +12 -0
  5. data/app/assets/javascripts/rocket_job_mission_control/datatable.js +40 -0
  6. data/app/assets/javascripts/rocket_job_mission_control/dirmon_entries.js +16 -0
  7. data/app/assets/javascripts/rocket_job_mission_control/selectize.js +6 -0
  8. data/app/controllers/rocket_job_mission_control/active_workers_controller.rb +16 -5
  9. data/app/controllers/rocket_job_mission_control/application_controller.rb +2 -0
  10. data/app/controllers/rocket_job_mission_control/dirmon_entries_controller.rb +47 -67
  11. data/app/controllers/rocket_job_mission_control/jobs_controller.rb +113 -19
  12. data/app/controllers/rocket_job_mission_control/servers_controller.rb +71 -28
  13. data/app/datatables/rocket_job_mission_control/abstract_datatable.rb +3 -3
  14. data/app/datatables/rocket_job_mission_control/active_workers_datatable.rb +8 -14
  15. data/app/datatables/rocket_job_mission_control/dirmon_entries_datatable.rb +7 -15
  16. data/app/datatables/rocket_job_mission_control/jobs_datatable.rb +128 -13
  17. data/app/datatables/rocket_job_mission_control/servers_datatable.rb +13 -15
  18. data/app/helpers/rocket_job_mission_control/application_helper.rb +58 -0
  19. data/app/helpers/rocket_job_mission_control/jobs_helper.rb +15 -7
  20. data/app/helpers/rocket_job_mission_control/servers_helper.rb +1 -1
  21. data/app/models/rocket_job_mission_control/job_sanitizer.rb +47 -0
  22. data/app/models/rocket_job_mission_control/query.rb +24 -18
  23. data/app/views/layouts/rocket_job_mission_control/application.html.erb +43 -0
  24. data/app/views/layouts/rocket_job_mission_control/partials/_flash.html.erb +20 -0
  25. data/app/views/layouts/rocket_job_mission_control/partials/_header.html.erb +45 -0
  26. data/app/views/layouts/rocket_job_mission_control/partials/_sidebar.html.erb +12 -0
  27. data/app/views/rocket_job_mission_control/active_workers/index.html.erb +40 -0
  28. data/app/views/rocket_job_mission_control/dirmon_entries/_form.html.erb +60 -0
  29. data/app/views/rocket_job_mission_control/dirmon_entries/_sidebar.html.erb +38 -0
  30. data/app/views/rocket_job_mission_control/dirmon_entries/_status.html.erb +17 -0
  31. data/app/views/rocket_job_mission_control/dirmon_entries/edit.html.erb +4 -0
  32. data/app/views/rocket_job_mission_control/dirmon_entries/index.html.erb +33 -0
  33. data/app/views/rocket_job_mission_control/dirmon_entries/new.html.erb +8 -0
  34. data/app/views/rocket_job_mission_control/dirmon_entries/show.html.erb +29 -0
  35. data/app/views/rocket_job_mission_control/jobs/_pagination.html.erb +26 -0
  36. data/app/views/rocket_job_mission_control/jobs/_sidebar.html.erb +32 -0
  37. data/app/views/rocket_job_mission_control/jobs/_status.html.erb +42 -0
  38. data/app/views/rocket_job_mission_control/jobs/edit.html.erb +32 -0
  39. data/app/views/rocket_job_mission_control/jobs/exception.html.erb +19 -0
  40. data/app/views/rocket_job_mission_control/jobs/exceptions.html.erb +40 -0
  41. data/app/views/rocket_job_mission_control/jobs/index.html.erb +33 -0
  42. data/app/views/rocket_job_mission_control/jobs/show.html.erb +68 -0
  43. data/app/views/rocket_job_mission_control/servers/_sidebar.html.erb +31 -0
  44. data/app/views/rocket_job_mission_control/servers/index.html.erb +56 -0
  45. data/config/locales/en.yml +3 -10
  46. data/config/routes.rb +20 -17
  47. data/lib/rocket_job_mission_control/engine.rb +10 -0
  48. data/lib/rocket_job_mission_control/version.rb +1 -1
  49. data/test/compare_hashes.rb +17 -0
  50. data/test/controllers/rocket_job_mission_control/application_controller_test.rb +49 -0
  51. data/test/controllers/rocket_job_mission_control/dirmon_entries_controller_test.rb +417 -0
  52. data/test/controllers/rocket_job_mission_control/jobs_controller_test.rb +363 -0
  53. data/test/controllers/rocket_job_mission_control/servers_controller_test.rb +251 -0
  54. data/test/helpers/rocket_job_mission_control/application_helper_test.rb +54 -0
  55. data/test/helpers/rocket_job_mission_control/jobs_helper_test.rb +85 -0
  56. data/test/helpers/rocket_job_mission_control/pagination_helper_test.rb +23 -0
  57. data/test/helpers/rocket_job_mission_control/servers_helper_test.rb +64 -0
  58. data/test/helpers/rocket_job_mission_control/slices_helper_test.rb +30 -0
  59. data/test/models/rocket_job_mission_control/job_sanitizer_test.rb +92 -0
  60. data/test/models/rocket_job_mission_control/query_test.rb +136 -0
  61. data/test/test_helper.rb +23 -0
  62. metadata +75 -175
  63. data/app/assets/javascripts/rocket_job_mission_control/base.js.coffee +0 -11
  64. data/app/assets/javascripts/rocket_job_mission_control/datatable.js.coffee +0 -33
  65. data/app/assets/javascripts/rocket_job_mission_control/dirmon_entries.js.coffee +0 -13
  66. data/app/assets/javascripts/rocket_job_mission_control/selectize.js.coffee +0 -5
  67. data/app/assets/stylesheets/rocket_job_mission_control/jquery.bootstrap-touchspin.scss +0 -45
  68. data/app/controllers/rocket_job_mission_control/dirmon_entries/index_filters_controller.rb +0 -45
  69. data/app/controllers/rocket_job_mission_control/jobs/failures_controller.rb +0 -30
  70. data/app/controllers/rocket_job_mission_control/jobs/index_filters_controller.rb +0 -90
  71. data/app/controllers/rocket_job_mission_control/servers/index_filters_controller.rb +0 -49
  72. data/app/datatables/rocket_job_mission_control/completed_jobs_datatable.rb +0 -27
  73. data/app/datatables/rocket_job_mission_control/interrupted_jobs_datatable.rb +0 -26
  74. data/app/datatables/rocket_job_mission_control/queued_jobs_datatable.rb +0 -23
  75. data/app/datatables/rocket_job_mission_control/running_jobs_datatable.rb +0 -47
  76. data/app/datatables/rocket_job_mission_control/scheduled_jobs_datatable.rb +0 -31
  77. data/app/models/job_failures.rb +0 -20
  78. data/app/models/job_sanitizer.rb +0 -17
  79. data/app/views/layouts/rocket_job_mission_control/application.html.haml +0 -45
  80. data/app/views/layouts/rocket_job_mission_control/partials/_header.html.haml +0 -32
  81. data/app/views/layouts/rocket_job_mission_control/partials/_sidebar.html.haml +0 -11
  82. data/app/views/rocket_job_mission_control/active_workers/index.html.haml +0 -24
  83. data/app/views/rocket_job_mission_control/dirmon_entries/_form.html.haml +0 -37
  84. data/app/views/rocket_job_mission_control/dirmon_entries/_properties.html.haml +0 -30
  85. data/app/views/rocket_job_mission_control/dirmon_entries/_sidebar.html.haml +0 -27
  86. data/app/views/rocket_job_mission_control/dirmon_entries/_status.html.haml +0 -23
  87. data/app/views/rocket_job_mission_control/dirmon_entries/edit.html.haml +0 -4
  88. data/app/views/rocket_job_mission_control/dirmon_entries/index.html.haml +0 -18
  89. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/disabled.html.haml +0 -17
  90. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/enabled.html.haml +0 -17
  91. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/failed.html.haml +0 -17
  92. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/pending.html.haml +0 -17
  93. data/app/views/rocket_job_mission_control/dirmon_entries/new.html.haml +0 -6
  94. data/app/views/rocket_job_mission_control/dirmon_entries/show.html.haml +0 -23
  95. data/app/views/rocket_job_mission_control/jobs/_sidebar.html.haml +0 -28
  96. data/app/views/rocket_job_mission_control/jobs/_status.html.haml +0 -45
  97. data/app/views/rocket_job_mission_control/jobs/edit.html.haml +0 -34
  98. data/app/views/rocket_job_mission_control/jobs/exceptions.html.haml +0 -29
  99. data/app/views/rocket_job_mission_control/jobs/failures/_pagination.html.haml +0 -16
  100. data/app/views/rocket_job_mission_control/jobs/failures/index.html.haml +0 -32
  101. data/app/views/rocket_job_mission_control/jobs/index.html.haml +0 -25
  102. data/app/views/rocket_job_mission_control/jobs/index_filters/aborted.html.haml +0 -23
  103. data/app/views/rocket_job_mission_control/jobs/index_filters/completed.html.haml +0 -24
  104. data/app/views/rocket_job_mission_control/jobs/index_filters/failed.html.haml +0 -23
  105. data/app/views/rocket_job_mission_control/jobs/index_filters/paused.html.haml +0 -23
  106. data/app/views/rocket_job_mission_control/jobs/index_filters/queued.html.haml +0 -24
  107. data/app/views/rocket_job_mission_control/jobs/index_filters/running.html.haml +0 -25
  108. data/app/views/rocket_job_mission_control/jobs/index_filters/scheduled.html.haml +0 -24
  109. data/app/views/rocket_job_mission_control/jobs/show.html.haml +0 -51
  110. data/app/views/rocket_job_mission_control/servers/_actions.html.haml +0 -9
  111. data/app/views/rocket_job_mission_control/servers/_sidebar.html.haml +0 -20
  112. data/app/views/rocket_job_mission_control/servers/index.html.haml +0 -37
  113. data/app/views/rocket_job_mission_control/servers/index_filters/paused.html.haml +0 -37
  114. data/app/views/rocket_job_mission_control/servers/index_filters/running.html.haml +0 -37
  115. data/app/views/rocket_job_mission_control/servers/index_filters/starting.html.haml +0 -37
  116. data/app/views/rocket_job_mission_control/servers/index_filters/stopping.html.haml +0 -37
  117. data/spec/controllers/application_controller_spec.rb +0 -47
  118. data/spec/controllers/dirmon_entries/index_filters_controller_spec.rb +0 -77
  119. data/spec/controllers/dirmon_entries_controller_spec.rb +0 -383
  120. data/spec/controllers/jobs/failures_controller_spec.rb +0 -82
  121. data/spec/controllers/jobs/index_filters_controller_spec.rb +0 -66
  122. data/spec/controllers/jobs_controller_spec.rb +0 -172
  123. data/spec/controllers/workers/index_filters_controller_spec.rb +0 -59
  124. data/spec/controllers/workers_controller_spec.rb +0 -125
  125. data/spec/dummy/Rakefile +0 -7
  126. data/spec/dummy/config.ru +0 -4
  127. data/spec/dummy/config/application.rb +0 -26
  128. data/spec/dummy/config/boot.rb +0 -5
  129. data/spec/dummy/config/database.yml +0 -25
  130. data/spec/dummy/config/environment.rb +0 -5
  131. data/spec/dummy/config/environments/test.rb +0 -37
  132. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  133. data/spec/dummy/config/initializers/session_store.rb +0 -3
  134. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  135. data/spec/dummy/config/mongoid.yml +0 -88
  136. data/spec/dummy/config/routes.rb +0 -3
  137. data/spec/dummy/config/secrets.yml +0 -22
  138. data/spec/dummy/config/symmetric-encryption.yml +0 -8
  139. data/spec/dummy/db/test.sqlite3 +0 -0
  140. data/spec/dummy/log/development.log +0 -0
  141. data/spec/dummy/log/test.log +0 -118933
  142. data/spec/helpers/application_helper_spec.rb +0 -58
  143. data/spec/helpers/jobs_helper_spec.rb +0 -35
  144. data/spec/helpers/pagination_helper_spec.rb +0 -21
  145. data/spec/helpers/servers_helper_spec.rb +0 -16
  146. data/spec/helpers/slices_helper_spec.rb +0 -33
  147. data/spec/models/job_failures_spec.rb +0 -14
  148. data/spec/models/job_sanitizer_spec.rb +0 -16
  149. data/spec/rails_helper.rb +0 -47
  150. data/spec/spec_helper.rb +0 -84
  151. data/vendor/assets/javascripts/jquery.bootstrap-touchspin.js +0 -686
  152. data/vendor/assets/javascripts/prism.js +0 -6
  153. data/vendor/assets/stylesheets/jquery.bootstrap-touchspin.css +0 -45
  154. data/vendor/assets/stylesheets/prism.scss +0 -160
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70e693d49e4ca57ddb518fbd75c3b66facbe134d
4
- data.tar.gz: f2d480f5f2f19fdb8106f5d258173b05b66e6d11
3
+ metadata.gz: 841a844611078eb6e374b46c7da8026adb5e1af4
4
+ data.tar.gz: 810b1f18daf8ebf333a5cace7771f97294aaaee9
5
5
  SHA512:
6
- metadata.gz: 6e040ed3c8d00608471dc4c55e07b4b28f17731ed07ab2c6309663993f91323e8f348816d4b2de37e9f9290ccc5c3bec7eda905227a76ac29bff082e4fc6abd4
7
- data.tar.gz: f6871621fb675475d9733cd181c108a6d7ad3877b65a8a47128f68ef5b8eaaedb26859df81a511c4fb37a4487a4ca465339f5bb044b903736e95e84fa79d5367
6
+ metadata.gz: 53d73b5170970540fb19bc514cb319b3f3924799f5a0fec97f1d4a0a83da57d93b97d53197f7ea3fc544e9fcc4ad7102bd5c461d42eab8215b1536ff7bfe3d9b
7
+ data.tar.gz: 9c869b611740289e4fc9743bd80980e297d72324cca4c0cb4dc578bfcd3cfc5cd0c26f0c6d7a9492d390977938ac98f5d69edcda64e909b83bbbbfa9aa976828
data/Rakefile CHANGED
@@ -1,12 +1,8 @@
1
- APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
1
+ APP_RAKEFILE = File.expand_path('../rjmc/Rakefile', __FILE__)
2
2
  load 'rails/tasks/engine.rake'
3
3
 
4
+ require 'rake/testtask'
4
5
  require_relative 'lib/rocket_job_mission_control/version'
5
- require 'rspec/core'
6
- require 'rspec/core/rake_task'
7
-
8
- task spec: 'app:spec'
9
- task default: :spec
10
6
 
11
7
  task :gem do
12
8
  system 'gem build rocketjob_mission_control.gemspec'
@@ -18,3 +14,11 @@ task publish: :gem do
18
14
  system "gem push rocketjob_mission_control-#{RocketJobMissionControl::VERSION}.gem"
19
15
  system "rm rocketjob_mission_control-#{RocketJobMissionControl::VERSION}.gem"
20
16
  end
17
+
18
+ Rake::TestTask.new(:test) do |t|
19
+ t.pattern = 'test/**/*_test.rb'
20
+ t.verbose = true
21
+ t.warning = false
22
+ end
23
+
24
+ task default: :test
@@ -15,10 +15,11 @@
15
15
  //= require dataTables/jquery.dataTables
16
16
  //= require dataTables/extras/dataTables.responsive
17
17
  //= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
18
+ //
19
+ // Selectize is used by Array builder in application_helper#editable_field_html
18
20
  //= require microplugin
19
21
  //= require sifter
20
22
  //= require selectize
21
- //= require jquery.bootstrap-touchspin
22
- //= require bootstrap-sprockets
23
- //= require prism
23
+ // End selectize dependencies
24
+ //
24
25
  //= require_tree .
@@ -0,0 +1,12 @@
1
+ $(document).ready(() => toggleCanvas());
2
+
3
+ var toggleCanvas = () =>
4
+ $('[data-toggle=offcanvas]').click(function () {
5
+ $(this).toggleClass('visible-xs text-center');
6
+ $(this).find('i').toggleClass('fa-chevron-right fa-chevron-left');
7
+ $('.row-offcanvas').toggleClass('active');
8
+ $('#lg-menu').toggleClass('hidden-xs').toggleClass('visible-xs');
9
+ $('#xs-menu').toggleClass('visible-xs').toggleClass('hidden-xs');
10
+ return $('#btnShow').toggle();
11
+ })
12
+ ;
@@ -0,0 +1,40 @@
1
+ var RjmcDatatable = class RjmcDatatable {
2
+ constructor(table, columns, opts) {
3
+ this.reloadTable = this.reloadTable.bind(this);
4
+ if (opts == null) { opts = {}; }
5
+ this.table = $(table);
6
+ this.columns = columns;
7
+ this.ordering = opts.ordering != null ? opts.ordering : true;
8
+ this.searching = opts.searching != null ? opts.searching : true;
9
+ this.pageLength = opts.pageLength != null ? opts.pageLength : 100;
10
+ this.order = opts.order != null ? opts.order : [];
11
+ this.reload = $("[data-behavior='reload']");
12
+ this.initializeTable();
13
+ this.setEvents();
14
+ }
15
+
16
+ initializeTable() {
17
+ return this.data = this.table.DataTable({
18
+ pagingType: 'full_numbers',
19
+ pageLength: this.pageLength,
20
+ responsive: true,
21
+ ajax: this.table.data('source'),
22
+ processing: true,
23
+ serverSide: true,
24
+ columns: this.columns,
25
+ ordering: this.ordering,
26
+ searching: this.searching,
27
+ order: this.order
28
+ });
29
+ }
30
+
31
+ setEvents() {
32
+ return this.reload.on('click', this.reloadTable);
33
+ }
34
+
35
+ reloadTable() {
36
+ let icon = this.reload.find('i');
37
+ icon.addClass('fa-spin');
38
+ return this.data.ajax.reload(() => icon.removeClass('fa-spin'));
39
+ }
40
+ };
@@ -0,0 +1,16 @@
1
+ $(document).on('ready', function() {
2
+ $('.filter .state-toggle').on('change', function() {
3
+ let active_states = $('.filter :checked');
4
+ let param_string = "?";
5
+ active_states.each((_, state) => param_string += `states[]=${$(state).attr('id')}&`);
6
+ return window.location.href = window.location.href.replace( /[\?#].*|$/, param_string );
7
+ });
8
+
9
+ if ($('#properties').length) {
10
+ return $('#properties').on('click', function() {
11
+ let params = $('#new_rocket_job_dirmon_entry').serialize();
12
+ let new_dirmon_path = $('#properties').data('url') + `?${params}`;
13
+ return window.location = new_dirmon_path;
14
+ });
15
+ }
16
+ });
@@ -0,0 +1,6 @@
1
+ $(document).on('ready', () =>
2
+ $('select.selectize').selectize({
3
+ create: true,
4
+ hideSelected: true
5
+ })
6
+ );
@@ -1,14 +1,25 @@
1
1
  module RocketJobMissionControl
2
2
  class ActiveWorkersController < RocketJobMissionControl::ApplicationController
3
- # The list of workers actively processing jobs
4
- # [Array[Array<server_name [String], job [RocketJob::Job], slice_id [String]]]
5
3
  def index
6
- @active_workers = RocketJob::ActiveWorker.all
7
- @query = RocketJobMissionControl::Query.new(@active_workers, name: :asc)
4
+ @server_name = params[:server_name]
5
+ if job_id = params[:job_id]
6
+ @job = RocketJob::Job.find(job_id)
7
+ end
8
8
 
9
9
  respond_to do |format|
10
10
  format.html
11
- format.json { render(json: ActiveWorkersDatatable.new(view_context, @query)) }
11
+ format.json do
12
+ # The list of workers actively processing jobs. Sorted by longest running workers first.
13
+ active_workers =
14
+ if @job
15
+ @job.rocket_job_active_workers
16
+ else
17
+ RocketJob::ActiveWorker.all(@server_name).sort { |a, b| b.duration_s <=> a.duration_s }
18
+ end
19
+
20
+ query = RocketJobMissionControl::Query.new(active_workers)
21
+ render(json: ActiveWorkersDatatable.new(view_context, query))
22
+ end
12
23
  end
13
24
  end
14
25
  end
@@ -1,5 +1,7 @@
1
1
  module RocketJobMissionControl
2
2
  class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+
3
5
  around_action :with_time_zone
4
6
 
5
7
  private
@@ -1,16 +1,31 @@
1
- require 'csv'
2
1
  module RocketJobMissionControl
3
2
  class DirmonEntriesController < RocketJobMissionControl::ApplicationController
4
- before_filter :find_entry_or_redirect, except: [:index, :new, :create]
5
- before_filter :clean_values, only: [:create, :update]
3
+ before_filter :find_entry_or_redirect, except: [:index, :disabled, :enabled, :failed, :pending, :new, :create]
6
4
  before_filter :show_sidebar
7
5
 
8
6
  def index
9
- @query = RocketJobMissionControl::Query.new(RocketJob::DirmonEntry.all, name: :asc)
10
- respond_to do |format|
11
- format.html
12
- format.json { render(json: DirmonEntriesDatatable.new(view_context, @query)) }
13
- end
7
+ @data_table_url = dirmon_entries_url(format: 'json')
8
+ render_datatable(RocketJob::DirmonEntry.all, 'All')
9
+ end
10
+
11
+ def disabled
12
+ @data_table_url = disabled_dirmon_entries_url(format: 'json')
13
+ render_datatable(RocketJob::DirmonEntry.disabled, 'Disabled')
14
+ end
15
+
16
+ def enabled
17
+ @data_table_url = enabled_dirmon_entries_url(format: 'json')
18
+ render_datatable(RocketJob::DirmonEntry.enabled, 'Enabled')
19
+ end
20
+
21
+ def failed
22
+ @data_table_url = failed_dirmon_entries_url(format: 'json')
23
+ render_datatable(RocketJob::DirmonEntry.failed, 'Failed')
24
+ end
25
+
26
+ def pending
27
+ @data_table_url = pending_dirmon_entries_url(format: 'json')
28
+ render_datatable(RocketJob::DirmonEntry.pending, 'Pending')
14
29
  end
15
30
 
16
31
  def show
@@ -27,11 +42,11 @@ module RocketJobMissionControl
27
42
 
28
43
  def create
29
44
  @dirmon_entry = RocketJob::DirmonEntry.new(dirmon_params)
30
-
31
- parse_and_assign_properties
45
+ if properties = params[:rocket_job_dirmon_entry][:properties]
46
+ @dirmon_entry.properties = JobSanitizer.sanitize(properties, @dirmon_entry.job_class, @dirmon_entry, false)
47
+ end
32
48
 
33
49
  if @dirmon_entry.errors.empty? && @dirmon_entry.save
34
- flash[:success] = t(:success, scope: [:dirmon_entry, :create])
35
50
  redirect_to(dirmon_entry_path(@dirmon_entry))
36
51
  else
37
52
  render :new
@@ -40,8 +55,6 @@ module RocketJobMissionControl
40
55
 
41
56
  def destroy
42
57
  @dirmon_entry.destroy
43
- flash[:success] = t(:success, scope: [:dirmon_entry, :destroy])
44
-
45
58
  redirect_to(dirmon_entries_path)
46
59
  end
47
60
 
@@ -49,10 +62,11 @@ module RocketJobMissionControl
49
62
  end
50
63
 
51
64
  def update
52
- @dirmon_entry.attributes = dirmon_params
53
- parse_and_assign_properties
54
- if @dirmon_entry.errors.empty? && @dirmon_entry.save
55
- flash[:success] = t(:success, scope: [:dirmon_entry, :update])
65
+ if properties = params[:rocket_job_dirmon_entry][:properties]
66
+ @dirmon_entry.properties = JobSanitizer.sanitize(properties, @dirmon_entry.job_class, @dirmon_entry, false)
67
+ end
68
+
69
+ if @dirmon_entry.errors.empty? && @dirmon_entry.valid? && @dirmon_entry.save
56
70
  redirect_to(rocket_job_mission_control.dirmon_entry_path(@dirmon_entry))
57
71
  else
58
72
  render :edit
@@ -62,7 +76,6 @@ module RocketJobMissionControl
62
76
  def enable
63
77
  if @dirmon_entry.may_enable?
64
78
  @dirmon_entry.enable!
65
- flash[:success] = t(:success, scope: [:dirmon_entry, :enable])
66
79
  redirect_to(rocket_job_mission_control.dirmon_entry_path(@dirmon_entry))
67
80
  else
68
81
  flash[:alert] = t(:failure, scope: [:dirmon_entry, :enable])
@@ -73,7 +86,6 @@ module RocketJobMissionControl
73
86
  def disable
74
87
  if @dirmon_entry.may_disable?
75
88
  @dirmon_entry.disable!
76
- flash[:success] = t(:success, scope: [:dirmon_entry, :disable])
77
89
  redirect_to(rocket_job_mission_control.dirmon_entry_path(@dirmon_entry))
78
90
  else
79
91
  flash[:alert] = t(:failure, scope: [:dirmon_entry, :disable])
@@ -92,65 +104,33 @@ module RocketJobMissionControl
92
104
  @dirmon_sidebar = true
93
105
  end
94
106
 
95
- def parse_and_assign_properties
96
- properties = params[:rocket_job_dirmon_entry].fetch(:properties, {})
97
- properties.each_pair do |property, value|
98
- if key = @dirmon_entry.job_class.fields[property]
99
- if key.type == Hash
100
- begin
101
- @dirmon_entry.properties[property] = JSON.parse(value)
102
- rescue JSON::ParserError => e
103
- @dirmon_entry.errors.add(:properties, e.message)
104
- end
105
- else
106
- @dirmon_entry.properties[property] = value
107
- end
108
- end
109
- end
110
- end
111
-
112
- # Returns [Array<String>] an array from the supplied string
113
- # String can also be in JSON format
114
- def parse_array_element(value, attribute, could_be_singleton = false)
115
- return if value.blank?
116
- begin
117
- JSON.parse(value)
118
- rescue JSON::ParserError => e
119
- begin
120
- values = CSV.parse(value).first.collect { |col| JSON.parse("[#{col.to_s.strip}]").first }
121
- could_be_singleton && (values.size == 1) ? values.first : values
122
- rescue Exception => exc
123
- @dirmon_entry.errors.add(attribute, e.message)
124
- @dirmon_entry.errors.add(attribute, exc.message)
125
- value
126
- end
127
- end
128
- end
129
-
130
- def clean_values
131
- params[:rocket_job_dirmon_entry].fetch(:properties, {}).each_pair do |param, value|
132
- params[:rocket_job_dirmon_entry][:properties].delete(param) if value.blank?
133
- end
134
- end
135
-
136
107
  def find_entry_or_redirect
137
- @dirmon_entry = RocketJob::DirmonEntry.find(params[:id])
138
-
139
- if @dirmon_entry.nil?
108
+ unless @dirmon_entry = RocketJob::DirmonEntry.where(id: params[:id]).first
140
109
  flash[:alert] = t(:failure, scope: [:dirmon_entry, :find], id: params[:id])
141
110
 
142
111
  redirect_to(dirmon_entries_path)
143
112
  end
144
113
  end
145
114
 
146
- def dirmons_params
147
- params.fetch(:states, [])
148
- end
149
-
150
115
  def dirmon_params
151
116
  params
152
117
  .fetch(:rocket_job_dirmon_entry, {})
153
118
  .permit(:name, :archive_directory, :pattern, :job_class_name)
154
119
  end
120
+
121
+ def render_datatable(entries, description)
122
+ respond_to do |format|
123
+ format.html do
124
+ @description = description
125
+ render :index
126
+ end
127
+ format.json do
128
+ query = RocketJobMissionControl::Query.new(entries, name: :asc)
129
+ query.search_columns = [:job_class_name, :name, :pattern]
130
+ query.display_columns = %w[name _type pattern]
131
+ render(json: DirmonEntriesDatatable.new(view_context, query))
132
+ end
133
+ end
134
+ end
155
135
  end
156
136
  end
@@ -1,20 +1,68 @@
1
1
  module RocketJobMissionControl
2
2
  class JobsController < RocketJobMissionControl::ApplicationController
3
- before_filter :find_job_or_redirect, except: [:index]
3
+ before_filter :find_job_or_redirect, except: [:index, :aborted, :completed, :failed, :paused, :queued, :running, :scheduled]
4
4
  before_filter :show_sidebar
5
5
  rescue_from StandardError, with: :error_occurred
6
6
 
7
7
  def index
8
- @query = RocketJobMissionControl::Query.new(RocketJob::Job.all, id: :desc)
9
- respond_to do |format|
10
- format.html
11
- format.json { render(json: JobsDatatable.new(view_context, @query)) }
12
- end
8
+ jobs = RocketJob::Job.all.only(JobsDatatable::ALL_FIELDS)
9
+ @data_table_url = jobs_url(format: 'json')
10
+
11
+ render_datatable(jobs, 'All', JobsDatatable::ALL_COLUMNS, id: :desc)
12
+ end
13
+
14
+ def running
15
+ jobs = RocketJob::Job.running.only(JobsDatatable::RUNNING_FIELDS)
16
+ @data_table_url = running_jobs_url(format: 'json')
17
+
18
+ render_datatable(jobs, 'Running', JobsDatatable::RUNNING_COLUMNS, started_at: :desc)
19
+ end
20
+
21
+ def paused
22
+ jobs = RocketJob::Job.paused.only(JobsDatatable::COMMON_FIELDS)
23
+ @data_table_url = paused_jobs_url(format: 'json')
24
+
25
+ render_datatable(jobs, 'Paused', JobsDatatable::PAUSED_COLUMNS, completed_at: :desc)
26
+ end
27
+
28
+ def completed
29
+ jobs = RocketJob::Job.completed.only(JobsDatatable::COMMON_FIELDS)
30
+ @data_table_url = completed_jobs_url(format: 'json')
31
+
32
+ render_datatable(jobs, 'Completed', JobsDatatable::COMPLETED_COLUMNS, completed_at: :desc)
33
+ end
34
+
35
+ def aborted
36
+ jobs = RocketJob::Job.aborted.only(JobsDatatable::COMMON_FIELDS)
37
+ @data_table_url = aborted_jobs_url(format: 'json')
38
+
39
+ render_datatable(jobs, 'Aborted', JobsDatatable::ABORTED_COLUMNS, completed_at: :desc)
40
+ end
41
+
42
+ def failed
43
+ jobs = RocketJob::Job.failed.only(JobsDatatable::COMMON_FIELDS)
44
+ @data_table_url = failed_jobs_url(format: 'json')
45
+
46
+ render_datatable(jobs, 'Failed', JobsDatatable::FAILED_COLUMNS, completed_at: :desc)
47
+ end
48
+
49
+ def queued
50
+ jobs = RocketJob::Job.queued_now.only(JobsDatatable::QUEUED_FIELDS)
51
+ @data_table_url = queued_jobs_url(format: 'json')
52
+
53
+ render_datatable(jobs, 'Queued', JobsDatatable::QUEUED_COLUMNS, completed_at: :desc)
54
+ end
55
+
56
+ def scheduled
57
+ jobs = RocketJob::Job.scheduled.only(JobsDatatable::SCHEDULED_FIELDS)
58
+ @data_table_url = scheduled_jobs_url(format: 'json')
59
+
60
+ render_datatable(jobs, 'Scheduled', JobsDatatable::SCHEDULED_COLUMNS, run_at: :asc)
13
61
  end
14
62
 
15
63
  def update
16
- JobSanitizer.new(params).sanitize
17
- if @job.update_attributes(job_params)
64
+ permitted_params = JobSanitizer.sanitize(params[:job], @job.class, @job)
65
+ if @job.errors.empty? && @job.valid? && @job.update_attributes(permitted_params)
18
66
  redirect_to job_path(@job)
19
67
  else
20
68
  render :edit
@@ -23,7 +71,6 @@ module RocketJobMissionControl
23
71
 
24
72
  def abort
25
73
  @job.abort!
26
-
27
74
  redirect_to(job_path(@job))
28
75
  end
29
76
 
@@ -34,25 +81,22 @@ module RocketJobMissionControl
34
81
 
35
82
  def retry
36
83
  @job.retry!
37
-
38
84
  redirect_to(job_path(@job))
39
85
  end
40
86
 
41
87
  def pause
42
88
  @job.pause!
43
-
44
89
  redirect_to(job_path(@job))
45
90
  end
46
91
 
47
92
  def resume
48
93
  @job.resume!
49
-
50
94
  redirect_to(job_path(@job))
51
95
  end
52
96
 
53
97
  def run_now
54
98
  @job.unset(:run_at) if @job.scheduled?
55
- redirect_to scheduled_jobs_path
99
+ redirect_to(job_path(@job))
56
100
  end
57
101
 
58
102
  def fail
@@ -71,6 +115,31 @@ module RocketJobMissionControl
71
115
  @exceptions = @job.input.group_exceptions
72
116
  end
73
117
 
118
+ def exception
119
+ error_type = params[:error_type]
120
+ offset = params.fetch(:offset, 0).to_i
121
+
122
+ unless error_type.present?
123
+ flash[:notice] = t(:no_errors, scope: [:job, :failures])
124
+ redirect_to(job_path(@job))
125
+ end
126
+
127
+ scope = @job.input.failed.where('exception.class_name' => error_type)
128
+ count = scope.count
129
+ unless count > 0
130
+ flash[:notice] = t(:no_errors, scope: [:job, :failures])
131
+ redirect_to(job_path(@job))
132
+ end
133
+
134
+ current_failure = scope.order(_id: 1).limit(1).skip(offset).first
135
+ @failure_exception = current_failure.try!(:exception)
136
+
137
+ @pagination = {
138
+ offset: offset,
139
+ total: (count - 1),
140
+ }
141
+ end
142
+
74
143
  private
75
144
 
76
145
  def show_sidebar
@@ -85,12 +154,8 @@ module RocketJobMissionControl
85
154
  end
86
155
  end
87
156
 
88
- def jobs_params
89
- params.fetch(:states, [])
90
- end
91
-
92
157
  def job_params
93
- params.require(:job).permit(RocketJob::Job.user_editable_fields)
158
+ params.require(:job).permit(@job.class.user_editable_fields)
94
159
  end
95
160
 
96
161
  def error_occurred(exception)
@@ -100,8 +165,37 @@ module RocketJobMissionControl
100
165
  logger.error "Error loading a job. #{exception.class}: #{exception.message}\n#{(exception.backtrace || []).join("\n")}"
101
166
  end
102
167
  flash[:danger] = 'Error loading jobs.'
103
- raise exception if Rails.env.development?
168
+ raise exception if Rails.env.development? || Rails.env.test?
104
169
  redirect_to :back
105
170
  end
171
+
172
+ def render_datatable(jobs, description, columns, sort_order)
173
+ respond_to do |format|
174
+ format.html do
175
+ @description = description
176
+ @columns = columns
177
+ @table_layout = build_table_layout(columns)
178
+ render :index
179
+ end
180
+ format.json do
181
+ query = RocketJobMissionControl::Query.new(jobs, sort_order)
182
+ query.search_columns = [:_type, :description]
183
+ query.display_columns = columns.collect { |c| c[:field] }.compact
184
+ render(json: JobsDatatable.new(view_context, query, columns))
185
+ end
186
+ end
187
+ end
188
+
189
+ def build_table_layout(columns)
190
+ index = 0
191
+ columns.collect do |column|
192
+ h = {data: index.to_s}
193
+ h[:width] = column[:width] if column.has_key?(:width)
194
+ h[:orderable] = column[:orderable] if column.has_key?(:orderable)
195
+ index += 1
196
+ h
197
+ end
198
+ end
199
+
106
200
  end
107
201
  end