def run(self): while True: self.event.wait() self.logger.info("QueueuFiller: started in thread %s.", self.ident) self.publish(actions.message("queueuFiller: started in " "server thread %s." % self.ident)) alert_counter = 0 while self.number_of_listeners() > 0: self.logger.info("QueueFiller: %s listeners, %s threads.", self.number_of_listeners(), threading.active_count()) self.publish(actions.add_point("memusage", int(time.time()) * 1000, random.random())) self.publish(actions.add_point("listeners", int(time.time()) * 1000, random.random())) tweetdata = offline_tweets.cache[int(random.random() * 200)][4] try: self.publish(actions.add_tweetlist_tweet("allTweets", json.loads(tweetdata))) except ValueError: # json.loads throws a ValueError for some tweets that # apparantly contain invalid json. pass if random.random() > .9: alert_counter += 1 self.publish(actions.alert("Random alert %s!" % alert_counter, "myAlerter")) time.sleep(1) self.logger.info("QueueFiller: stopped in thread %s.", self.ident)
def run(self): print("queueuFiller: started in thread %s." % self.ident) self._send_to_all_listeners(actions.message("queueuFiller: started in " "server thread %s." % self.ident)) self._send_to_all_listeners(actions.create_general_chart("chart1", self.chart_options)) while True: self._send_to_all_listeners(actions.add_point("mychart", int(time.time()) * 1000, random.random())) time.sleep(1)
def run(self): while True: self.event.wait() self.logger.info("QueueuFiller: started in thread %s.", self.ident) self.publish( actions.message("queueuFiller: started in " "server thread %s." % self.ident)) alert_counter = 0 while self.number_of_listeners() > 0: self.logger.info("QueueFiller: %s listeners, %s threads.", self.number_of_listeners(), threading.active_count()) self.publish( actions.add_point("memusage", int(time.time()) * 1000, random.random())) self.publish( actions.add_point("listeners", int(time.time()) * 1000, random.random())) tweetdata = offline_tweets.cache[int(random.random() * 200)][4] try: self.publish( actions.add_tweetlist_tweet("allTweets", json.loads(tweetdata))) except ValueError: # json.loads throws a ValueError for some tweets that # apparantly contain invalid json. pass if random.random() > .9: alert_counter += 1 self.publish( actions.alert("Random alert %s!" % alert_counter, "myAlerter")) time.sleep(1) self.logger.info("QueueFiller: stopped in thread %s.", self.ident)
def test_add_point_wrong_y_coord(self): self.assertEqual(actions.add_point("one", 2, "three"), {"event": "message", "data": ['{"messageText":"Python function add_point ' 'called with wrong y_coord type."}']}, "Message should exactly be like second arg.")
def test_add_point_empty_chartid(self): self.assertEqual(actions.add_point("", 2, 3), {"event": "message", "data": ['{"messageText":"Python function add_point ' 'called with empty chart_id."}']}, "Message should exactly be like second arg.")
def test_add_point(self): self.assertEqual(actions.add_point("chart1", 4, 5), {"event": "addpoint", "data": ['{"X":4,"Y":5,"chartID":"chart1"}']}, "Message should exactly be like second arg.")