Skip to content

Instantly share code, notes, and snippets.

@Marahin

Marahin/ci.rb Secret

Created November 16, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marahin/6f68bc9cfa2527cde06091d95afd88b8 to your computer and use it in GitHub Desktop.
Save Marahin/6f68bc9cfa2527cde06091d95afd88b8 to your computer and use it in GitHub Desktop.
#!/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