Пример #1
0
 def _clients_write_message(self, message=None):
     message = jsondumps(message)
     for client in self.clients:
         try:
             client.write_message(message)
         except:
             pass
Пример #2
0
def start_server(*args, **kwargs):
    global __SERVER
    debugcolorizer('### SERVER ###', fg='black', bg='blue')
    logging.info('Starting server...')

    if not settings.is_options_parsed():
        options.parse_command_line()
        settings.options_parse(options.options.as_dict())

    settings_dict = settings.as_dict()

    try:
        module = None
        for key in constants.APPLICATION_CLASS_LIST:
            if key in settings_dict:
                cls = settings_dict[key]
                module = import_object(cls)
                break
        application = module(**settings_dict)
    except:
        application = ServerApplication(**settings_dict)

    if settings.DEBUG:
        code = jsoncolorize(jsondumps(settings_dict, indent=2, sort_keys=True))
        logging.debug(' * Settings:\n\n%s\n\n', code)

    http_server = httpserver.HTTPServer(
        application, **{
            'xheaders': settings.XHEADERS,
            'ssl_options': application.ssl_options
        })

    io_loop = ioloop.IOLoop.current()
    application.set_exit_callback(partial(_stop_loop, io_loop))

    with stack_context.NullContext():
        if settings.PREFORK_PROCESS > -1:
            http_server.bind(settings.PORT)
            http_server.start(settings.PREFORK_PROCESS)
        else:
            http_server.listen(settings.PORT)

    yield gen.Task(application.start)

    __SERVER = ServerEnvironment(settings.SERVER_NAME, application,
                                 http_server, io_loop)

    url = 'http://{domain}:{port}'.format(**settings_dict)
    logging.info('%s v%s', __SERVER.name.upper(), __SERVER.version.value)
    logging.info('Running server on %s', url)
    logging.info('--')

    if not compat.WIN and settings.DEBUG and not settings.DISABLE_BROWSER:
        import subprocess
        subprocess.Popen(['open', url])

    yield gen.Task(lambda callback: None)
Пример #3
0
 def commit(self, action='NONE', **kwargs):
     data = dict(action=action)
     if not action.startswith('SYS_'):
         data['node_id'] = self.node_id
         data['node'] = self.node_info
     data.update(kwargs)
     if 'callback' in data:
         del data['callback']
     data = jsondumps(data)
     logging.debug(' * Commit(%s):  %s | %s', _CHANNEL, action, data)
     response = yield gen.Task(self.publisher.publish, _CHANNEL, data)
     raise gen.Return(response)
Пример #4
0
 def _fetch_pull(self, **kwargs):
     global _NODES, _FALLEN_NODES
     if self._SHUTTING_DOWN is False:
         logging.debug(' * Recovering nodes...')
         _NODES = {}
         _FALLEN_NODES = set()
         response = yield gen.Task(self.publisher.keys, 'node:*')
         if self.node_id not in response:
             logging.error(' ! Node not registered: %s', self.node_id)
             raise gen.Return(None)
         logging.debug(' * Recovered nodes:')
         for node in response:
             value = yield gen.Task(self.publisher.get, node)
             _data, data = strucloads(value)
             node_id = _NODE.format(ip=data.ip, port=data.port)
             if node_id != self.node_id:
                 self.nodes[node_id] = _data
         logging.debug(' : Not found' if not self.nodes else jsondumps(
             self.nodes, indent=2))
     raise gen.Return(True)
Пример #5
0
 def register(self, **kwargs):
     response = yield gen \
         .Task(self.publisher.set, self.node_id, jsondumps(self.node_info))
     logging.info(' # Register: %s', response)
     raise gen.Return(response)
Пример #6
0
def debugdumps(value):
    logging.debug(jsondumps(value))
Пример #7
0
def printdumps(value):
    print jsondumps(value)
Пример #8
0
def trace(value=None):
    if value is not None:
        if isinstance(value, (tuple, list, dict, set)):
            value = jsondumps(value)
        logging.error(value)
    logging.error(traceback.format_exc())
Пример #9
0
 def json_dumps(self, value, **kwargs):
     if not compat.ujson_available:
         kwargs.setdefault('separators', (',', ':'))
     return jsondumps(value, **kwargs)
Пример #10
0
 def to_json(self):
     return jsondumps(self.to_object())