Class: Deployed::RunController

Inherits:
ApplicationController show all
Defined in:
app/controllers/deployed/run_controller.rb

Overview

Provides a centralized way to run all ‘kamal [command]` executions and streams to the browser

Defined Under Namespace

Classes: ConcurrentProcessRunning

Instance Method Summary collapse

Instance Method Details

#cancelObject

Endpoint to cancel currently running process



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/deployed/run_controller.rb', line 27

def cancel
  pid = stored_pid
  if process_running?
    # If a process is running, get the PID and attempt to kill it
    begin
      Process.kill('TERM', stored_pid)
    rescue Errno::ESRCH
    ensure
      release_process
    end
  end
  render json: { message: pid }
end

#executeObject

Endpoint to execute the kamal command



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/deployed/run_controller.rb', line 10

def execute
  raise(ConcurrentProcessRunning) if process_running?
  release_process if stored_pid
  File.write(current_log_file, '')

  # Fork a child process
  Deployed::CurrentExecution.child_pid = fork do
    exec("bundle exec rake deployed:execute_and_log['#{command}']")
  end

  lock_process
  render json: { message: 'OK' }
rescue ConcurrentProcessRunning
  render json: { message: 'EXISTING PROCESS' }
end