提交 41ae432f 编写于 作者: M Matthew Draper

Shuffle a few things in aid of easier debugging

* Don't swallow output -- if there is any, it's probably useful
* Wait for the process to finish
* Use IPC instead of a sleep
* No need for a pidfile
上级 2ca8545e
......@@ -19,28 +19,38 @@ def clear_jobs
end
def start_workers
fork do
logfile = Rails.root.join("log/sidekiq.log").to_s
pidfile = Rails.root.join("tmp/sidekiq.pid").to_s
::Process.daemon(true, true)
[$stdout, $stderr].each do |io|
File.open(logfile, 'ab') do |f|
io.reopen(f)
end
io.sync = true
end
continue_read, continue_write = IO.pipe
death_read, death_write = IO.pipe
@pid = fork do
continue_read.close
death_write.close
# Celluloid & Sidekiq are not warning-clean :(
$VERBOSE = false
$stdin.reopen('/dev/null')
$stdout.sync = true
$stderr.sync = true
logfile = Rails.root.join("log/sidekiq.log").to_s
Sidekiq::Logging.initialize_logger(logfile)
File.open(File.expand_path(pidfile), 'w') do |f|
f.puts ::Process.pid
end
self_read, self_write = IO.pipe
trap "TERM" do
self_write.puts("TERM")
end
Thread.new do
begin
death_read.read
rescue Exception
end
self_write.puts("TERM")
end
require 'celluloid'
Celluloid.logger = nil
require 'sidekiq/launcher'
sidekiq = Sidekiq::Launcher.new({queues: ["integration_tests"],
environment: "test",
......@@ -51,23 +61,29 @@ def start_workers
Sidekiq::Scheduled.const_set :INITIAL_WAIT, 1
begin
sidekiq.run
continue_write.puts "started"
while readable_io = IO.select([self_read])
signal = readable_io.first[0].gets.strip
raise Interrupt if signal == "TERM"
end
rescue Interrupt
sidekiq.stop
exit(0)
end
sidekiq.stop
exit!
end
sleep 1
continue_write.close
death_read.close
@worker_lifeline = death_write
raise "Failed to start worker" unless continue_read.gets == "started\n"
end
def stop_workers
pidfile = Rails.root.join("tmp/sidekiq.pid").to_s
Process.kill 'TERM', File.open(pidfile).read.to_i
FileUtils.rm_f pidfile
rescue
if @pid
Process.kill 'TERM', @pid
Process.wait @pid
end
end
def can_run?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册