Class: RemoteRailsRakeRunner::RunnerController

Inherits:
ApplicationController show all
Defined in:
app/controllers/remote_rails_rake_runner/runner_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/remote_rails_rake_runner/runner_controller.rb', line 7

def index
  tasks = Rake.application.tasks.map do |t|
    {
        name: t.to_s,
        args: t.arg_names,
        description: t.comment,
    }
  end

  render json: tasks
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/remote_rails_rake_runner/runner_controller.rb', line 19

def run
  success = true
  rake_tasks = Rake.application.tasks
  task = rake_tasks.find { |t| t.name == params[:task] }
  return head :not_found unless task

  begin
    output = capture_stdout do
      override_env(params[:environment]) { task.invoke(*(params[:args] || '').split(',')) }
    end
  rescue => e
    success = false
    output = e.inspect
  ensure
    rake_tasks.each { |task| task.reenable }
  end

  render json: {success: success, output: output}
end