Sha256: cead1271d02c98beb26664730a60a8f275336bd938c2af8e193c330de9f74a35
Contents?: true
Size: 1.03 KB
Versions: 18
Compression:
Stored size: 1.03 KB
Contents
require "timeout" class ExternalSneaker attr_accessor :worker_pid, :start_command def initialize(start_command) fail ArgumentError, "start_command was expected" if start_command.nil? self.start_command = start_command end def start puts "Trying to start #{start_command}..." self.worker_pid = fork do start_child end at_exit do stop_child end end private def start_child exec({ "RAILS_ENV" => Rails.env, "WORKERS" => "TestWorker" }, start_command) end def stop_child # rubocop:disable AbcSize puts "Trying to stop #{start_command}, pid: #{worker_pid}" # send TERM and wait for exit Process.kill("TERM", worker_pid) begin Timeout.timeout(10) do Process.waitpid(worker_pid) puts "Process #{start_command} stopped successfully" end rescue Timeout::Error # Kill process if could not exit in 10 seconds puts "Sending KILL signal to #{start_command}, pid: #{worker_pid}" Process.kill("KILL", worker_pid) end end end
Version data entries
18 entries across 18 versions & 1 rubygems