Permalink
Browse files

Tasks are marked done by its msg_uuid

  • Loading branch information...
krakatoa committed Feb 20, 2013
1 parent f05778d commit d18641a88805da4fdb77e4a2229b5936d15e2116
Showing with 19 additions and 8 deletions.
  1. +5 −6 lib/server/channel.rb
  2. +14 −2 lib/stats_collector.rb
View
@@ -41,7 +41,7 @@ def box_start
# TODO Route messages according class_name and object_uuid
Cucub::Server::Channel.inner_inbound.send_string("#{destination.klass}##{destination.uid} #{msg}")
- Cucub::Server.instance.stats_collector.sent_msg_to(destination.uid, destination.klass)
+ Cucub::Server.instance.stats_collector.sent_msg_to(destination.uid, destination.klass, message.uuid)
@socket.send_string("Cucub::Reply ok!")
}
@@ -84,12 +84,11 @@ def inner_outbound_start
Cucub::Server.instance.register_vm(message.body.additionals)
when "ready"
puts "READY: #{message.inspect}"
- message.body.additionals.each do |done|
- ready = Cucub::Message.parse(done)
- ready.unlock(:msgpack)
- # puts "==== #{ready.inspect}"
- Cucub::Server.instance.stats_collector.mark_done(message.header.from.object_uuid, ready.header.to.class_name.underscore)
+
+ message.body.additionals.each do |done_uuid|
+ Cucub::Server.instance.stats_collector.mark_done(message.header.from.object_uuid, Cucub::Server.instance.stats_collector.class_for_msg(done_uuid), done_uuid)
end
+
puts "STATS: #{Cucub::Server.instance.stats_collector.vm_stats}"
end
end
View
@@ -4,31 +4,43 @@ class StatsCollector
def initialize
@stats = { :vm_stats => {}, :server_stats => {:sent => 0} }
+ @pending = { }
end
def register_vm(vm)
vm.assigned = 0
vm.done = 0
@stats[:vm_stats][vm.klass] ||= []
@stats[:vm_stats][vm.klass] << vm
+
+ @pending[vm.klass] = []
end
- def sent_msg_to(uid, klass)
+ def sent_msg_to(uid, klass, msg_uuid)
vm = @stats[:vm_stats][klass].select {|v| v.uid == uid}[0]
vm.assigned += 1
@stats[:server_stats][:sent] += 1
+
+ @pending[klass] << msg_uuid
+ end
+
+ def class_for_msg(msg_uuid)
+ @pending.select{|key, value| value.include?(msg_uuid)}.keys[0].underscore
end
def sent_messages
@stats[:server_stats][:sent]
end
- def mark_done(uid, klass)
+ def mark_done(uid, klass, msg_uuid)
vm = @stats[:vm_stats][klass].select {|v| v.uid == uid}[0]
vm.done += 1
vm.assigned -= 1
puts "#{vm.klass} #{uid}: #{vm.assigned} assigned; #{vm.done} done"
+
+ @pending.select{|key, value| value.include?(msg_uuid)}.values[0].delete(msg_uuid)
+ puts "pending_for: #{@pending}"
end
def vm_stats

0 comments on commit d18641a

Please sign in to comment.