Class: Buildbox::Canceler

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/buildbox/canceler.rb

Instance Method Summary collapse

Constructor Details

#initialize(build) ⇒ Canceler

Returns a new instance of Canceler.



8
9
10
# File 'lib/buildbox/canceler.rb', line 8

def initialize(build)
  @build = build
end

Instance Method Details

#cancelObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/buildbox/canceler.rb', line 12

def cancel
  @build.cancel_started = true

  # Zombie child process killing is not currently supported on Windows.
  unless ChildProcess.platform == :windows
    # Store all the child processes before we stop so we can reap them after.
    # A new process may start up between this and the process stopping,
    # but that should be OK for now.
    child_processes = process_map[@build.process.pid]
  end

  # Stop the process
  Buildbox.logger.info "Cancelling build #{@build.namespace}/#{@build.id} with PID #{@build.process.pid}"
  @build.process.stop

  # If it hasn't stopped yet, wait until it has.
  sleep 1 until @build.exited?

  kill_processes(child_processes) if child_processes
end