Example #1
0
def make_agent(
    exit_stack: asyncs.LABELS.exit_stack,
    server,
    params,
    agent_queue: g1.asyncs.agents.parts.LABELS.agent_queue,
    shutdown_queue: g1.asyncs.agents.parts.LABELS.shutdown_queue,
):
    exit_stack.enter_context(server)
    server.socket.listen(params.url.get())
    for _ in range(params.parallelism.get()):
        agent_queue.spawn(server.serve)
    shutdown_queue.put_nonblocking(server.shutdown)
Example #2
0
def make_agent(
    exit_stack: asyncs.LABELS.exit_stack,
    publisher,
    params,
    agent_queue: g1.asyncs.agents.parts.LABELS.agent_queue,
    shutdown_queue: g1.asyncs.agents.parts.LABELS.shutdown_queue,
):
    exit_stack.enter_context(publisher)
    if params.send_timeout.get() is not None:
        publisher.socket.send_timeout = parts_utils.to_milliseconds_int(
            params.send_timeout.get())
    publisher.socket.listen(params.url.get())
    agent_queue.spawn(publisher.serve)
    shutdown_queue.put_nonblocking(publisher.shutdown)
Example #3
0
def make_agent(
    exit_stack: asyncs.LABELS.exit_stack,
    subscriber,
    params,
    agent_queue: g1.asyncs.agents.parts.LABELS.agent_queue,
    shutdown_queue: g1.asyncs.agents.parts.LABELS.shutdown_queue,
):
    exit_stack.enter_context(subscriber)
    if params.recv_timeout.get() is not None:
        subscriber.socket.recv_timeout = parts_utils.to_milliseconds_int(
            params.recv_timeout.get())
    for url in params.urls.get():
        subscriber.socket.dial(url)
    agent_queue.spawn(subscriber.serve)
    shutdown_queue.put_nonblocking(subscriber.shutdown)
Example #4
0
def make_server(
    exit_stack: asyncs.LABELS.exit_stack,
    create_engine,
    publisher,
    agent_queue: g1.asyncs.agents.parts.LABELS.agent_queue,
    shutdown_queue: g1.asyncs.agents.parts.LABELS.shutdown_queue,
):
    server = exit_stack.enter_context(
        servers.DatabaseServer(engine=create_engine(), publisher=publisher))
    agent_queue.spawn(server.serve)
    shutdown_queue.put_nonblocking(server.shutdown)
    return g1_servers.Server(
        server,
        interfaces.DatabaseRequest,
        interfaces.DatabaseResponse,
        capnps.WIRE_DATA,
        warning_level_exc_types=(
            interfaces.InvalidRequestError,
            interfaces.KeyNotFoundError,
            interfaces.LeaseNotFoundError,
            interfaces.TransactionNotFoundError,
            interfaces.TransactionTimeoutError,
        ),
        invalid_request_error=interfaces.InvalidRequestError(),
        internal_server_error=interfaces.InternalError(),
    )
Example #5
0
def configure_client(
    exit_stack: asyncs.LABELS.exit_stack,
    client,
    params,
):
    exit_stack.enter_context(client)
    if params.send_timeout.get() is not None:
        client.socket.send_timeout = parts_utils.to_milliseconds_int(
            params.send_timeout.get())
    if params.recv_timeout.get() is not None:
        client.socket.recv_timeout = parts_utils.to_milliseconds_int(
            params.recv_timeout.get())
    if params.resend_time.get() is not None:
        client.socket.resend_time = parts_utils.to_milliseconds_int(
            params.resend_time.get())
    for url in params.urls.get():
        client.socket.dial(url)
Example #6
0
def make_server_socket(
    exit_stack: asyncs.LABELS.exit_stack,
    params,
    ssl_context,
):
    return exit_stack.enter_context(
        sockets.make_server_socket(
            (params.host.get(), params.port.get()),
            reuse_address=params.reuse_address.get(),
            reuse_port=params.reuse_port.get(),
            ssl_context=ssl_context,
        ),
    )
Example #7
0
def make_console(
    exit_stack: asyncs.LABELS.exit_stack,
    agent_queue: g1.asyncs.agents.parts.LABELS.agent_queue,
    shutdown_queue: g1.asyncs.agents.parts.LABELS.shutdown_queue,
    params,
):
    if not params.enable.get():
        return
    # Use mktemp because when binding to a unix domain socket, it is an
    # error when file exists.
    socket_path = tempfile.mktemp(
        dir=ASSERT.predicate(params.socket_dir_path.get(), Path.is_dir),
        prefix=params.socket_file_prefix.get(),
    )
    exit_stack.callback(Path(socket_path).unlink, missing_ok=True)
    server = servers.SocketServer(
        exit_stack.enter_context(
            sockets.make_server_socket(socket_path, family=socket.AF_UNIX), ),
        SocketConsoleHandler(banner='', exitmsg=''),
    )
    agent_queue.spawn(server.serve)
    shutdown_queue.put_nonblocking(server.shutdown)