def main(): """Main implementation.""" args = parse_args() if args.log_file is not None: log = open(args.log_file, 'a') else: log = None logger = base.setup_logging( stream=log, level=args.log_level, ) try: logger.info('Startup') logger.debug('Args: %s', args) server = Server(args.timeout) def exit_handler(signal, frame): server.close_server() signal.signal(signal.SIGINT, exit_handler) signal.signal(signal.SIGTERM, exit_handler) response_context = {} request_context = { 'users': {}, 'rooms': {}, } bind_addr, bind_port = args.new.split(':') bind_port = int(bind_port) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((bind_addr, bind_port)) s.listen(10) s.setblocking(False) server.register( pollable.SocketListen( s, pollable.HttpSocket, server, request_context, )) server.logger.debug( 'Created new listener socket %s:%s', bind_addr, bind_port, ) server.run() except Exception as e: logger.debug('Exception', exc_info=True) finally: for h in logger.handlers: h.close() logger.removeHandler(h)
def __init__(self, year): boundary = Boundary(13.381014, 100.950397, 14.284958, 99.869143) interval = 60 * 1 super(GreaterBangkokAccidentRetriever, self).__init__(boundary, interval) self.logger = setup_logging('GreaterBangkokAccidentRetriever') self.year = year self.logger.debug('using year=%s', year)
def __init__(self, binding_keys): self.logger = setup_logging('DeploymentMaster') self.message_queue = queue.PriorityQueue() self.accident_event_consumer = AccidentEventConsumer(self.message_queue, binding_keys) self.team_uuid = str(uuid.uuid4()) self.player_count = 5 self.logger.debug('initiated')
def __init__(self, group_uuid, player_id, boundary): super(Player, self).__init__(target=self.consume, daemon=True) self.group_uuid = group_uuid self.player_id = player_id self.boundary = boundary self.object_name = '{}.player{}'.format(group_uuid, player_id) self.queue_name = self.object_name self.logger = setup_logging(self.object_name) self.state = PlayerState(self.object_name, boundary) self.job_queue = queue.Queue() self.logger.debug('initiated')
def __init__(self, player_name, boundary): self.player_name = player_name self.boundary = boundary self.logger = setup_logging('{}.state'.format(player_name)) self.status = Status.IDLE self.status_since = self.now() self.completion_time = self.now() self.lat = boundary.left + (random.betavariate(2, 2) * (boundary.right - boundary.left)) self.long = boundary.bottom + (random.betavariate(2, 2) * (boundary.top - boundary.bottom)) self.plan = None self.logger.debug('starting at lat=%s, long=%s', self.lat, self.long) self.logger.debug('initiated')
def __init__(self): self.logger = setup_logging('GameMaster') connection = RabbitMQ.setup_connection() def close_connection(): self.logger.debug('Closing connection') connection.close() atexit.register(close_connection) channel = connection.channel() channel.queue_declare(queue=RabbitMQ.game_master_queue_name()) self.connection = connection self.channel = channel
def __init__(self, boundary, interval): self.logger = setup_logging('AccidentRetriever') self.boundary = boundary self.interval = interval connection = RabbitMQ.setup_connection() self.connection = connection self.channel = self.connection.channel() self.channel.exchange_declare( exchange=RabbitMQ.accident_exchange_name(), exchange_type='topic') def close_connection(): self.logger.debug('Closing connection') connection.close() atexit.register(close_connection)
def __init__(self): boundary = Boundary(3.870733, 100.711638, 2.533530, 101.970674) interval = 60 * 10 super(KlangValleyAccidentRetriever, self).__init__(boundary, interval) self.logger = setup_logging('KlangValleyAccidentRetriever')
logging.info("Master.start_slave: new slave started: %r" % p) slave = dict(id=slave_id, process=p, job=job, routing_key=routing_key, queue_name=queue_name) self.slaves.append(slave) return slave def command_start(): with BrokerConnection("amqp://*****:*****@localhost:5672//") as conn: Master(conn).run() def command_stop(): with BrokerConnection("amqp://*****:*****@localhost:5672//") as conn: publish_job(conn, dict(command="cancel"), "announce") if __name__ == '__main__': setup_logging(logging.INFO) command = "start" if len(sys.argv) > 1: command = sys.argv[1].lower() if command == "start": command_start() if command == "stop": command_stop() sys.exit(0) # vim: set ft=python ts=4 sw=4 expandtab :
def start_new_slave(job, queue_name, routing_key): setup_logging(level=logging.DEBUG) logger.info("Slave: start_new_slave: job=%r" % job) with BrokerConnection("amqp://*****:*****@localhost:5672//") as conn: Slave(conn, job, queue_name, routing_key).run()
def process_message(self, body, message): logger.info("Slave.process_message: message=%r" % message) logger.info("Slave.process_message: body =%r" % body) command = body.get("command", "print") logger.info("Slave: COMMAND %s" % command) if command == "print": print body if command == "quit": logger.info("Slave: QUITTING ...") self.should_stop = True message.ack() def start_new_slave(job, queue_name, routing_key): setup_logging(level=logging.DEBUG) logger.info("Slave: start_new_slave: job=%r" % job) with BrokerConnection("amqp://*****:*****@localhost:5672//") as conn: Slave(conn, job, queue_name, routing_key).run() if __name__ == '__main__': setup_logging(level=logging.DEBUG) start_new_slave({}, "slave-1", "slave-1") # vim: set ft=python ts=4 sw=4 expandtab :
def __init__(self, message_queue, binding_keys): super(AccidentEventConsumer, self).__init__() self.message_queue = message_queue self.logger = setup_logging('AccidentEventConsumer') self.binding_keys = binding_keys
def __init__(self): binding_keys = ['thailand.greater_bangkok'] super(NearestAssessorBangkokDeploymentMaster, self).__init__(binding_keys) self.logger = setup_logging('NearestAssessorBangkokDeploymentMaster') self.boundary = Boundary(13.381014, 100.950397, 14.284958, 99.869143)
def __init__(self, boundary, interval): self.r = random.Random(42) super(RandomAccidentRetriever, self).__init__(boundary, interval) self.logger = setup_logging('RandomAccidentRetriever')
def __init__(self): boundary = Boundary(3.398051, 101.433717, 2.776582, 101.995776) interval = 5 super(KlangValleyRandomAccidentRetriever, self).__init__(boundary, interval) self.logger = setup_logging('KlangValleyRandomAccidentRetriever')