Created
September 18, 2013 21:34
-
-
Save michaelglass/6616081 to your computer and use it in GitHub Desktop.
ugly, brutish DJ throughput task
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
task :dj_throughput, roles: :delayed_job do | |
last_reported = Time.now | |
completed = {} | |
run "tail -f #{shared_path}/log/delayed_job.log" do |channel, stream, data| | |
host = channel[:host] | |
trap("INT") { puts 'Interupted'; exit 0; } | |
if data =~ /completed after/ | |
completed[host] ||= 0 | |
completed[host] += 1 | |
end | |
now = Time.now | |
if now - last_reported > 5 | |
elapsed = now - last_reported | |
last_reported = now | |
total = 0 | |
# this string clears the screen so I don't have to use curses. google it! | |
puts "\e[H\e[2J" | |
completed.each do |host, num_completed| | |
total += num_completed | |
puts "#{host}: #{num_completed} in #{elapsed}, #{num_completed/elapsed} jobs/s" | |
end | |
completed = {} | |
puts "total: #{total} in #{elapsed}, #{total/elapsed} jobs/s" | |
end | |
break if stream == :err | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment