diff --git a/lib/que/command_line_interface.rb b/lib/que/command_line_interface.rb index 5a60014c..cf89c722 100644 --- a/lib/que/command_line_interface.rb +++ b/lib/que/command_line_interface.rb @@ -9,6 +9,23 @@ module CommandLineInterface # Have a sensible default require file for Rails. RAILS_ENVIRONMENT_FILE = './config/environment.rb' + class ThreadDumper + def self.call + thread_details = 'Dumping thread traces:\n' + Thread.list.each do |t| + thread_details = "\n\n## Thread TID-#{t.object_id.to_s(36)} #{t['label']} \n" + if t.backtrace + thread_details += t.backtrace.join("\n") + else + thread_details += "\tThread has no backtrace available\n" + end + end + + STDOUT.puts thread_details + IO.write("#{Dir.pwd}/thread_dump.txt", thread_details) + end + end + class << self # Need to rely on dependency injection a bit to make this method cleanly # testable :/ @@ -245,19 +262,7 @@ def parse( # It's a bit sloppy to use a global for this when a local variable would # do, but we want to stop the locker from the CLI specs, so... $stop_que_executable = false - %w[INT TERM].each { |signal| trap(signal) { $stop_que_executable = true } } - - trap("TTIN") do - puts 'Dumping thread traces:' - Thread.list.each do |t| - puts "## Thread TID-#{t.object_id.to_s(36)} #{t['label']}" - if t.backtrace - puts t.backtrace.join("\n") - else - puts "\tThread has no backtrace available" - end - end - end + %w[INT TERM].each { |signal| trap(signal) { ThreadDumper.call; $stop_que_executable = true } } output.puts( <<~STARTUP