GitHub

http_runner

API reference for http_runner.

A cluster runner whose RPCs travel over HTTP or WebSockets (Effect's HttpRunner).

layer_client_protocol_http / layer_client_protocol_websocket dial other runners at http(s)://host:port/path / ws(s)://host:port/path; to_http_effect / to_http_effect_websocket serve the runner protocol as an HTTP handler; layer_http_options / layer_websocket_options add it to the HttpRouter, and layer_http / layer_websocket serve it at / on the HttpServer. The *_client_only layers join the cluster as a sender only.

Values

AttributeTypeDescription
layer_client_protocol_http_defaultLayer[RpcClientProtocol, Never, RpcSerialization | HttpClient]

layer_client_protocol_http dialing runners over HTTP at /.

layer_client_protocol_websocket_defaultLayer[RpcClientProtocol, Never, RpcSerialization | WebSocketConstructor]

layer_client_protocol_websocket dialing runners over a WebSocket at /.

to_http_effectEffect[HttpEffect, Never, Scope | RpcSerialization | Sharding | MessageStorage]

The runner protocol served as an HTTP handler of POSTs, its server running in the current scope (Effect's HttpRunner.toHttpEffect).

to_http_effect_websocketEffect[HttpEffect, Never, Scope | RpcSerialization | Sharding | MessageStorage]

to_http_effect over WebSockets.

layer_clientLayer[Sharding | Runners, Never, ShardingConfig | RpcClientProtocol | MessageStorage | RunnerStorage | RunnerHealth]

Sharding and the RPC Runners over the RpcClientProtocol.

layer_httpLayer[Sharding | Runners, Never, RpcSerialization | ShardingConfig | HttpClient | HttpServer | MessageStorage | RunnerStorage | RunnerHealth]

A runner serving at / of the HttpServer and dialing others over HTTP.

layer_http_client_onlyLayer[Sharding | Runners, Never, RpcSerialization | ShardingConfig | HttpClient | MessageStorage | RunnerStorage]

A sender-only member of the cluster, dialing runners over HTTP.

layer_websocketLayer[Sharding | Runners, Never, RpcSerialization | ShardingConfig | WebSocketConstructor | HttpServer | MessageStorage | RunnerStorage | RunnerHealth]

A runner serving WebSockets at / of the HttpServer and dialing others over WebSockets.

layer_websocket_client_onlyLayer[Sharding | Runners, Never, RpcSerialization | ShardingConfig | WebSocketConstructor | MessageStorage | RunnerStorage]

A sender-only member of the cluster, dialing runners over WebSockets.

Functions

layer_client_protocol_http

layer_client_protocol_http(*, path, https=False) -> Layer[RpcClientProtocol, Never, RpcSerialization | HttpClient]

Dial runners over HTTP POSTs to path (https for TLS).

ParameterTypeDescription
pathstr
httpsbool = False

Returns Layer[RpcClientProtocol, Never, RpcSerialization | HttpClient]

def layer_client_protocol_http(
    *, path: str, https: bool = False
) -> Layer[RpcClientProtocol, Never, RpcSerialization | HttpClient]:
    """Dial runners over HTTP POSTs to ``path`` (``https`` for TLS)."""

    @gen
    def make_():
        serialization = yield from RpcSerialization()
        client = yield from HttpClient()
        return _http_client_protocol(serialization, client, path, https)

    return layer_.effect(RpcClientProtocol, make_)

layer_client_protocol_websocket

layer_client_protocol_websocket(*, path, https=False) -> Layer[RpcClientProtocol, Never, RpcSerialization | WebSocketConstructor]

Dial runners over WebSockets at path (https for wss).

ParameterTypeDescription
pathstr
httpsbool = False

Returns Layer[RpcClientProtocol, Never, RpcSerialization | WebSocketConstructor]

def layer_client_protocol_websocket(
    *, path: str, https: bool = False
) -> Layer[RpcClientProtocol, Never, RpcSerialization | WebSocketConstructor]:
    """Dial runners over WebSockets at ``path`` (``https`` for ``wss``)."""

    @gen
    def make_():
        serialization = yield from RpcSerialization()
        constructor = yield from WebSocketConstructor()

        def make_protocol(address: RunnerAddress) -> Effect[ClientProtocolService, Never, Scope]:
            @gen
            def connect():
                url = _url("wss" if https else "ws", address, path)
                socket = yield from make_web_socket(url).pipe(
                    provide_service(WebSocketConstructor, constructor)
                )
                return (
                    yield from make_protocol_socket()
                    .pipe(provide_service(Socket, socket))
                    .pipe(provide_service(RpcSerialization, serialization))
                )

            return connect

        return RpcClientProtocolService(make=make_protocol, codec_for=serialization.codec_for)

    return layer_.effect(RpcClientProtocol, make_)

layer_http_options

layer_http_options(*, path) -> Layer[Sharding | Runners, Never, _ServerNeeds | HttpRouter]

A runner serving the runner protocol on POSTs to path of the HttpRouter.

ParameterTypeDescription
pathstr

Returns Layer[Sharding | Runners, Never, _ServerNeeds | HttpRouter]

def layer_http_options(*, path: str) -> Layer[Sharding | Runners, Never, _ServerNeeds | HttpRouter]:
    """A runner serving the runner protocol on POSTs to ``path`` of the
    ``HttpRouter``."""
    return runner_server.layer_with_clients.pipe(layer_.provide(layer_protocol_http(path)))

layer_websocket_options

layer_websocket_options(*, path) -> Layer[Sharding | Runners, Never, _ServerNeeds | HttpRouter]

A runner serving the runner protocol on WebSockets at path of the HttpRouter.

ParameterTypeDescription
pathstr

Returns Layer[Sharding | Runners, Never, _ServerNeeds | HttpRouter]

def layer_websocket_options(
    *, path: str
) -> Layer[Sharding | Runners, Never, _ServerNeeds | HttpRouter]:
    """A runner serving the runner protocol on WebSockets at ``path`` of the
    ``HttpRouter``."""
    return runner_server.layer_with_clients.pipe(layer_.provide(layer_protocol_websocket(path)))