Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: None  |  size: 0.98 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def time_queue_chomping(size = 10)
  2.   if Resque.redis.llen("queue:robot_events").to_i > 0
  3.     puts "no way jose, the queue is full of junk!"
  4.     return
  5.   end
  6.   Rails.application.config.logger.level = Logger::WARN
  7.   ActiveRecord::Base.logger = ::Logger.new(StringIO.new)
  8.   t0 = Time.now.to_i
  9.   size.times { Resque.push("robot_events", :class => "RobotEventHandler", :args => [{:occurred_at => DateTime.now, :mailer => Mailer.first.attributes, :action => "fetch_top_line_data", :status => "success", :duration => "5", :response_queue => "ROBOT_EVENTS"}]) }
  10.   printed = []
  11.   while(Resque.redis.llen("queue:robot_events").to_i > 0) do
  12.     diff = Time.now.to_i - t0
  13.     if diff != 0 && (diff % 60) == 0 && !printed.include?(diff)
  14.       printed << diff
  15.       puts "1 minute has passed...#{Resque.redis.llen("queue:robot_events")} remain"
  16.     end
  17.   end
  18.   t1 = Time.now.to_i
  19.   puts "It took #{t1 - t0} seconds to process #{size} RobotEvents"
  20.   puts "Thats a rate of #{size*1.0/(t1-t0)} robot events per second"
  21. end