Skip to content

Instantly share code, notes, and snippets.

@michaelglass
Created September 18, 2013 21:34
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 michaelglass/6616081 to your computer and use it in GitHub Desktop.
Save michaelglass/6616081 to your computer and use it in GitHub Desktop.
ugly, brutish DJ throughput task
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