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
85 86 87 88 89 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 85 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
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 194 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
91 92 93 94 95 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 91 def destroy :destroy, @job @job.destroy redirect_to(jobs_path) end |
#edit ⇒ Object
132 133 134 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 132 def edit :edit, @job end |
#edit_slice ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 158 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
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 222 def exception :read, @job error_type = params[:error_type] offset = params.fetch(:offset, 0).to_i unless error_type.present? flash[:notice] = 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 > 0 flash[:notice] = 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
121 122 123 124 125 126 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 121 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
103 104 105 106 107 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 103 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
109 110 111 112 113 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 109 def resume :resume, @job @job.resume! redirect_to(job_path(@job)) end |
#retry ⇒ Object
97 98 99 100 101 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 97 def retry :retry, @job @job.retry! redirect_to(job_path(@job)) end |
#run_now ⇒ Object
115 116 117 118 119 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 115 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
128 129 130 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 128 def show :read, @job end |
#update ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 75 def update :update, @job permitted_params = JobSanitizer.sanitize(params[:job], @job.class, @job) if @job.errors.empty? && @job.valid? && @job.update_attributes(permitted_params) redirect_to job_path(@job) else render :edit end end |
#update_slice ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 171 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 # 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
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/rocket_job_mission_control/jobs_controller.rb', line 136 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['exception']['record_number'], offset: @offset, total: (scope.count - 1) } end |