diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-06-17 12:48:53 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-06-17 12:48:53 +0100 |
commit | a2fc458d4c1bc6027760546653cb153e775576ce (patch) | |
tree | f3af3775adab48d9a18495eeb410cf48269ffd9e /lib/mauve/processor.rb | |
parent | 4b39583e63b59d73e2855d776f7cca12d734f2af (diff) |
* Notifications are now run in their separate threads.
* Queues are now just arrays instead of "Queue"s
* Updated templates to be saner.
* Added flusing of queues when threads stop
Diffstat (limited to 'lib/mauve/processor.rb')
-rw-r--r-- | lib/mauve/processor.rb | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb index a46f229..083b9a1 100644 --- a/lib/mauve/processor.rb +++ b/lib/mauve/processor.rb @@ -19,26 +19,26 @@ module Mauve # @transmission_id_cache = {} @transmission_cache_expire_time = 300 - @sleep_interval = 1 + @transmission_cache_checked_at = Time.now end def main_loop - sz = Server.packet_buffer_size - - return if sz == 0 - - Timer.instance.freeze unless Timer.instance.frozen? - - logger.info("Buffer has #{sz} packets waiting...") + logger.info("Buffer has packets waiting...") if Server.packet_buffer_size > 0 # # Only do the loop a maximum of 10 times every @sleep_interval seconds # - - (sz > 50 ? 50 : sz).times do + 10.times do data, client, received_at = Server.packet_pop + # + # Uh-oh. Nil data? That's craaaazy + # + break if data.nil? + + Timer.instance.freeze unless Timer.instance.frozen? + @logger.debug("Got #{data.inspect} from #{client.inspect}") ip_source = "#{client[3]}:#{client[1]}" @@ -71,7 +71,6 @@ module Mauve ensure @transmission_id_cache[update.transmission_id.to_s] = MauveTime.now - end end @@ -85,6 +84,11 @@ module Mauve def expire_transmission_id_cache now = MauveTime.now + # + # Only check once every minute. + # + return unless (now - @transmission_cache_checked_at) > 60 + to_delete = [] @transmission_id_cache.each do |tid, received_at| @@ -94,7 +98,17 @@ module Mauve to_delete.each do |tid| @transmission_id_cache.delete(tid) end + + @transmission_cache_checked_at = now end + def stop + super + + # + # flush the queue + # + main_loop + end end end |