Class: MaintenanceTasks::RunsController Private

Inherits:
ApplicationController show all
Defined in:
app/controllers/maintenance_tasks/runs_controller.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class communicates with the Run model to persist info related to task runs. It defines actions for creating and pausing runs.

Constant Summary

Constants inherited from ApplicationController

ApplicationController::BULMA_CDN

Instance Method Summary collapse

Instance Method Details

#cancelObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Updates a Run status to cancelling.



39
40
41
42
43
44
# File 'app/controllers/maintenance_tasks/runs_controller.rb', line 39

def cancel
  @run.cancel
  redirect_to(task_path(@run.task_name))
rescue ActiveRecord::RecordInvalid => error
  redirect_to(task_path(@run.task_name), alert: error.message)
end

#create(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a Run for a given Task and redirects to the Task page.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/maintenance_tasks/runs_controller.rb', line 12

def create(&block)
  task = Runner.run(
    name: params.fetch(:task_id),
    csv_file: params[:csv_file],
    arguments: params.fetch(:task, {}).permit!.to_h,
    metadata: instance_exec(&MaintenanceTasks. || -> {}),
    &block
  )
  redirect_to(task_path(task))
rescue ActiveRecord::RecordInvalid => error
  redirect_to(task_path(error.record.task_name), alert: error.message)
rescue ActiveRecord::ValueTooLong => error
  task_name = params.fetch(:task_id)
  redirect_to(task_path(task_name), alert: error.message)
rescue Runner::EnqueuingError => error
  redirect_to(task_path(error.run.task_name), alert: error.message)
end

#pauseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Updates a Run status to paused.



31
32
33
34
35
36
# File 'app/controllers/maintenance_tasks/runs_controller.rb', line 31

def pause
  @run.pause
  redirect_to(task_path(@run.task_name))
rescue ActiveRecord::RecordInvalid => error
  redirect_to(task_path(@run.task_name), alert: error.message)
end

#resumeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resumes a previously paused Run.



47
48
49
50
51
52
53
54
# File 'app/controllers/maintenance_tasks/runs_controller.rb', line 47

def resume
  Runner.resume(@run)
  redirect_to(task_path(@run.task_name))
rescue ActiveRecord::RecordInvalid => error
  redirect_to(task_path(@run.task_name), alert: error.message)
rescue Runner::EnqueuingError => error
  redirect_to(task_path(@run.task_name), alert: error.message)
end