Skip to content

Commit

Permalink
Contain the logic to a class
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrypower committed Feb 1, 2024
1 parent 2b76613 commit bf02924
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions lib/que/command_line_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 :/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf02924

Please sign in to comment.