Пример #1
0
 def commit(self):
     for notification in self.pending_notifications:
         logger.info(
             "Publishing '%s' to '%s' with routing_key '%s'" %
             (notification['event_type'], self.exchange, self.queue_name))
         try:
             driver.send_notification(notification, self.queue_name,
                                      self.connection, self.exchange)
         except Exception as e:
             logger.exception(e)
 def commit(self):
     for notification in self.pending_notifications:
         logger.info("Publishing '%s' to '%s' with routing_key '%s'" %
                     (notification['event_type'], self.exchange,
                      self.queue_name))
         try:
             driver.send_notification(notification, self.queue_name,
                                      self.connection, self.exchange)
         except Exception as e:
             logger.exception(e)
Пример #3
0
exchange = driver.create_exchange("monitor", "topic")
queue_name = "monitor.info"
queue = driver.create_queue(queue_name, exchange, queue_name, channel=connection.channel())
queue.declare()

print "Usage: python event_pump.py <template_dir> <operations/hour> " "<realtime? 1/0>"
template_dir = sys.argv[1]
rate = int(sys.argv[2])
realtime = int(sys.argv[3]) == 1
print "Using template dir:", template_dir
print "Rate:", rate
print "Real-time?", realtime

g = notigen.EventGenerator(template_dir, rate)
now = datetime.datetime.utcnow()
start = now
end = now + datetime.timedelta(days=1)
nevents = 0
while now < end:
    e = g.generate(now)
    if e:
        nevents += len(e)
        for event in e:
            driver.send_notification(event, queue_name, connection, exchange)
            print event["timestamp"], event["event_type"]

    if realtime:
        now = datetime.datetime.utcnow()
    else:
        now = g.move_to_next_tick(now)