Class: RailsOpsDashboard::RakeTasksController

Inherits:
BaseController
  • Object
show all
Includes:
BackgroundTaskRunner
Defined in:
app/controllers/rails_ops_dashboard/rake_tasks_controller.rb

Constant Summary

Constants included from BackgroundTaskRunner

BackgroundTaskRunner::TASKS

Instance Method Summary collapse

Methods included from BackgroundTaskRunner

#run_in_background, #task_status

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/rails_ops_dashboard/rake_tasks_controller.rb', line 13

def execute
  task_name = params[:task_name]

  load_rake_tasks
  begin
    task = Rake::Task[task_name]
  rescue RuntimeError
    return redirect_to rake_tasks_path(message: "Task not found: #{task_name}", type: 'error')
  end

  unless custom_task?(task)
    return redirect_to rake_tasks_path(message: 'Cannot execute built-in tasks', type: 'error')
  end

  task_id = SecureRandom.hex(8)

  run_in_background(task_id, task_name) do
    task.reenable
    task.invoke
  end

  redirect_to rake_tasks_path(message: "Started: #{task_name}", type: 'info', task_id: task_id)
end

#indexObject



9
10
11
# File 'app/controllers/rails_ops_dashboard/rake_tasks_controller.rb', line 9

def index
  @rake_tasks = discover_rake_tasks
end

#statusObject



37
38
39
40
# File 'app/controllers/rails_ops_dashboard/rake_tasks_controller.rb', line 37

def status
  task = task_status(params[:task_id])
  render json: task || { status: 'not_found' }
end