-
-
Save Marahin/6f68bc9cfa2527cde06091d95afd88b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def kill_all_threads | |
Thread.list.each do |thread| | |
thread.exit unless thread == Thread.current | |
end | |
end | |
JOBS = [ | |
"bin/rspec_rerun spec", | |
"bin/quality" | |
].freeze | |
threads = [] | |
should_poll = true | |
JOBS.each do |job| | |
threads << Thread.new do | |
system(job) | |
end | |
end | |
begin | |
while should_poll do | |
threads_done = threads.select { |t| !t.alive? } | |
if threads_done.any? | |
threads_failed = threads_done.select{ |k| !k.value } | |
if threads_failed.any? | |
puts 'Detected failure!' | |
kill_all_threads | |
puts 'All threads should have been killed by now. Done!' | |
exit 1 | |
elsif threads_done.count == JOBS.count | |
puts 'All threads have finished. Done!' | |
should_poll = false | |
end | |
sleep 0.5 | |
end | |
end | |
rescue Interrupt | |
kill_all_threads | |
exit 130 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment