예제 #1
0
def _get_run_args(print_args: bool = True):
    """Fetch run args for jinad

    :param print_args: True if we want to print args to console
    :return: jinad args
    """
    from jina.helper import colored
    from daemon import daemon_logger

    parser = get_main_parser()
    from argparse import _StoreAction, _StoreTrueAction

    args, argv = parser.parse_known_args()
    # avoid printing for partial daemon (args.mode is set)
    if print_args and args.mode is None:

        default_args = {
            a.dest: a.default
            for a in parser._actions
            if isinstance(a, (_StoreAction, _StoreTrueAction))
        }

        with open(os.path.join(__resources_path__, 'jina.logo')) as fp:
            logo_str = fp.read()
        param_str = []
        for k, v in sorted(vars(args).items()):
            j = f'{k.replace("_", "-"): >30.30} = {str(v):30.30}'
            if default_args.get(k, None) == v:
                param_str.append('   ' + j)
            else:
                param_str.append('🔧️ ' + colored(j, 'blue', 'on_yellow'))
        param_str = '\n'.join(param_str)
        daemon_logger.info(
            f'\n{logo_str}\n▶️  {" ".join(sys.argv)}\n{param_str}\n')
    return args
예제 #2
0
파일: logs.py 프로젝트: srbhr/jina
    async def connect(self, websocket: WebSocket):
        """
        Register a new websocket.

        :param websocket: websocket to register
        """
        await websocket.accept()
        daemon_logger.info(
            '%s is connected to stream logs!' % _websocket_details(websocket)
        )
        self.active_connections.append(websocket)
예제 #3
0
파일: logs.py 프로젝트: srbhr/jina
    async def disconnect(self, websocket: WebSocket):
        """
        Disconnect a websocket.

        :param websocket: websocket to disconnect
        """
        if websocket in self.active_connections:
            self.active_connections.remove(websocket)
        if websocket.application_state != WebSocketState.DISCONNECTED:
            await websocket.close()
            daemon_logger.info('%s is disconnected' % _websocket_details(websocket))
예제 #4
0
async def startup():
    """Start the process"""
    from daemon import daemon_logger, jinad_args

    daemon_logger.info(f'''
Welcome to Jina daemon - the manager of distributed Jina
💬 Swagger UI     :\thttp://localhost:{jinad_args.port}/docs
📚 Redoc          :\thttp://localhost:{jinad_args.port}/redoc
🔒 Private address:\thttp://{get_internal_ip()}:{jinad_args.port}
🌐 Public address :\thttp://{get_public_ip()}:{jinad_args.port}''')
    from jina import __ready_msg__

    daemon_logger.success(__ready_msg__)
예제 #5
0
 def run(self) -> None:
     """
     Method representing the ConsumerThread's activity
     ConsumerThread is a daemon thread that waits for messages from the `__task_queue__`
     and starts a `DaemonWorker` for each message.
     """
     while True:
         try:
             workspace_id, files = __task_queue__.get()
             daemon_logger.info(
                 f'starting DaemonWorker{self._workers_count} for workspace {colored(workspace_id, "cyan")}'
             )
             DaemonWorker(id=workspace_id,
                          files=files,
                          name=str(self._workers_count))
             self._workers_count += 1
         except ValueError as e:
             daemon_logger.error(
                 f'got an invalid item in the queue. unable to process! {e!r}'
             )
         except Empty:
             pass