Class: RocketJobMissionControl::JobsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RocketJobMissionControl::JobsController
- Defined in:
- app/controllers/rocket_job_mission_control/jobs_controller.rb
Instance Method Summary collapse
- #abort ⇒ Object
- #aborted ⇒ Object
- #completed ⇒ Object
- #delete_line ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #edit_slice ⇒ Object
- #exception ⇒ Object
- #fail ⇒ Object
- #failed ⇒ Object
- #index ⇒ Object
- #pause ⇒ Object
- #paused ⇒ Object
- #queued ⇒ Object
- #resume ⇒ Object
- #retry ⇒ Object
- #run_now ⇒ Object
- #running ⇒ Object
- #scheduled ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #update_slice ⇒ Object
- #view_slice ⇒ Object
Instance Method Details
#abort ⇒ Object
88 89 90 91 92 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 88 def abort :abort, @job @job.abort! redirect_to(job_path(@job)) end |
#aborted ⇒ Object
47 48 49 50 51 52 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 47 def aborted jobs = RocketJob::Job.aborted.only(JobsDatatable::COMMON_FIELDS) @data_table_url = aborted_jobs_url(format: "json") render_datatable(jobs, "Aborted", JobsDatatable::ABORTED_COLUMNS, completed_at: :desc) end |
#completed ⇒ Object
40 41 42 43 44 45 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 40 def completed jobs = RocketJob::Job.completed.only(JobsDatatable::COMMON_FIELDS) @data_table_url = completed_jobs_url(format: "json") render_datatable(jobs, "Completed", JobsDatatable::COMPLETED_COLUMNS, completed_at: :desc) end |
#delete_line ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 200 def delete_line :edit_slice, @job # Params from the edit_slice form error_type = params[:error_type] offset = params.fetch(:offset, 0).to_i line_index = params[:line_index].to_i # Finds specific slice [Array] scope = @job.input.failed.where("exception.class_name" => error_type) slice = scope.order(_id: 1).limit(1).skip(offset).first # Finds and deletes line value = slice.to_a[line_index] slice.to_a.delete(value) # Assings full array back to slice slice.records = slice.to_a if slice.save logger.info("Line Deleted By #{login}, job: #{@job.id}, file_name: #{@job.upload_file_name}") redirect_to view_slice_job_path(@job, error_type: error_type) flash[:success] = "line removed" else flash[:danger] = "Error removing line." end end |
#destroy ⇒ Object
94 95 96 97 98 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 94 def destroy :destroy, @job @job.destroy redirect_to(jobs_path) end |
#edit ⇒ Object
135 136 137 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 135 def edit :edit, @job end |
#edit_slice ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 161 def edit_slice # We need all the instance varaibles from the view_slice (above) to able to # Build the form as an array but only display the bad line :edit_slice, @job error_type = params[:error_type] @line_index = params[:line_index].to_i @offset = params.fetch(:offset, 0).to_i scope = @job.input.failed.where("exception.class_name" => error_type) current_failure = scope.order(_id: 1).limit(1).skip(@offset).first @lines = current_failure.records @failure_exception = current_failure.try!(:exception) end |
#exception ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 228 def exception :read, @job error_type = params[:error_type] offset = params.fetch(:offset, 0).to_i unless error_type.present? flash[:warning] = t(:no_errors, scope: %i[job failures]) redirect_to(job_path(@job)) end scope = @job.input.failed.where("exception.class_name" => error_type) count = scope.count unless count.positive? flash[:warning] = t(:no_errors, scope: %i[job failures]) redirect_to(job_path(@job)) end current_failure = scope.order(_id: 1).limit(1).skip(offset).first @failure_exception = current_failure.try!(:exception) @pagination = { offset: offset, total: (count - 1) } end |
#fail ⇒ Object
124 125 126 127 128 129 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 124 def fail :fail, @job @job.fail! redirect_to(job_path(@job)) end |
#failed ⇒ Object
54 55 56 57 58 59 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 54 def failed jobs = RocketJob::Job.failed.only(JobsDatatable::COMMON_FIELDS) @data_table_url = failed_jobs_url(format: "json") render_datatable(jobs, "Failed", JobsDatatable::FAILED_COLUMNS, completed_at: :desc) end |
#index ⇒ Object
15 16 17 18 19 20 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 15 def index jobs = RocketJob::Job.all.only(JobsDatatable::ALL_FIELDS) @data_table_url = jobs_url(format: "json") render_datatable(jobs, "All", JobsDatatable::ALL_COLUMNS, id: :desc) end |
#pause ⇒ Object
106 107 108 109 110 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 106 def pause :pause, @job @job.pause! redirect_to(job_path(@job)) end |
#paused ⇒ Object
33 34 35 36 37 38 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 33 def paused jobs = RocketJob::Job.paused.only(JobsDatatable::COMMON_FIELDS) @data_table_url = paused_jobs_url(format: "json") render_datatable(jobs, "Paused", JobsDatatable::PAUSED_COLUMNS, completed_at: :desc) end |
#queued ⇒ Object
61 62 63 64 65 66 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 61 def queued jobs = RocketJob::Job.queued_now.only(JobsDatatable::QUEUED_FIELDS) @data_table_url = queued_jobs_url(format: "json") render_datatable(jobs, "Queued", JobsDatatable::QUEUED_COLUMNS, priority: :asc, created_at: :asc) end |
#resume ⇒ Object
112 113 114 115 116 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 112 def resume :resume, @job @job.resume! redirect_to(job_path(@job)) end |
#retry ⇒ Object
100 101 102 103 104 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 100 def retry :retry, @job @job.retry! redirect_to(job_path(@job)) end |
#run_now ⇒ Object
118 119 120 121 122 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 118 def run_now :run_now, @job @job.unset(:run_at) if @job.scheduled? redirect_to(job_path(@job)) end |
#running ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 22 def running # Prevent throttled jobs from displaying. jobs = RocketJob::Job. running. where(:started_at.lte => (Time.now - 0.1)). only(JobsDatatable::RUNNING_FIELDS) @data_table_url = running_jobs_url(format: "json") render_datatable(jobs, "Running", JobsDatatable::RUNNING_COLUMNS, priority: :asc, created_at: :asc) end |
#scheduled ⇒ Object
68 69 70 71 72 73 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 68 def scheduled jobs = RocketJob::Job.scheduled.only(JobsDatatable::SCHEDULED_FIELDS) @data_table_url = scheduled_jobs_url(format: "json") render_datatable(jobs, "Scheduled", JobsDatatable::SCHEDULED_COLUMNS, run_at: :asc) end |
#show ⇒ Object
131 132 133 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 131 def show :read, @job end |
#update ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 75 def update :update, @job permitted_params = JobSanitizer.sanitize(job_params, @job.class, @job) assign_job_values(@job, permitted_params) if @job.errors.empty? && @job.valid? && @job.save redirect_to job_path(@job) else render :edit end end |
#update_slice ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 174 def update_slice :update_slice, @job # Params from the edit_slice form error_type = params[:error_type] offset = params[:offset] updated_records = params["job"]["records"] # Finds specific slice [Array] slice = @job.input.failed.skip(offset).first # Converts \r\n line breaks to \n updated_records.each { |record| record.gsub(/\r\n/, "\n") } # Assings modified slice (from the form) back to slice slice.records = updated_records if slice.save logger.info("Slice Updated By #{login}, job: #{@job.id}, file_name: #{@job.upload_file_name}") flash[:success] = "slice updated" redirect_to view_slice_job_path(@job, error_type: error_type) else flash[:danger] = "Error updating slice." end end |
#view_slice ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 139 def view_slice # Params from RocketJob. Exceptions are grouped by class_name. # Scope: [[slice1], [slice2], [slice(n)] :view_slice, @job error_type = params[:error_type] scope = @job.input.failed.where("exception.class_name" => error_type) # Used by pagination to display the correct slice # Offset refers to the slice number from the array "scope". @offset = params.fetch(:offset, 0).to_i current_failure = scope.order(_id: 1).limit(1).skip(@offset).first # Instance variables to share with the view and pagination. @lines = current_failure.records @failure_exception = current_failure.try!(:exception) @view_slice_pagination = { record_number: current_failure.processing_record_number, offset: @offset, total: (scope.count - 1) } end |