Beispiel #1
0
 def setUp(self):
     conn = DjangoBrokerConnection()
     consumer = StatsConsumer(connection=conn)
     consumer.discard_all()
     conn.close()
     consumer.close()
     self.s = StatsCollector()
     self.assertEquals(self.s.total_tasks_processed, 0)
     self.assertEquals(self.s.total_tasks_processed_by_type, {})
     self.assertEquals(self.s.total_task_time_running, 0.0)
     self.assertEquals(self.s.total_task_time_running_by_type, {})
Beispiel #2
0
 def collect(self):
     """Collect any new statistics available since the last time
     :meth:`collect` was executed."""
     connection = DjangoBrokerConnection()
     consumer = StatsConsumer(connection=connection)
     it = consumer.iterqueue(infinite=False)
     for message in it:
         stats_entry = message.decode()
         stat_type = stats_entry["type"]
         if stat_type in self.allowed_types:
             # Decode keys to unicode for use as kwargs.
             data = dict((key.encode("utf-8"), value)
                             for key, value in stats_entry["data"].items())
             handler = getattr(self, stat_type)
             handler(**data)