oasislmf.utils.ping

Attributes

Functions

oasis_ping(data)

Sends a JSON message to either an HTTP endpoint, a websocket server, or a socket server.

oasis_ping_async(data)

Sends a ping without blocking the caller.

oasis_ping_socket(target, data)

Sends a JSON message to a target socket

oasis_ping_http(url, data)

Sends a JSON message to a target HTTP endpoint via POST.

oasis_ping_websocket(ws_url, data)

Sends a JSON message to a target websocket

Module Contents

oasislmf.utils.ping.logger[source]
oasislmf.utils.ping.oasis_ping(data)[source]

Sends a JSON message to either an HTTP endpoint, a websocket server, or a socket server.

If analysis_pk is in the data, targets are tried in order until one succeeds:
  • if OASIS_ANALYSIS_STATUS_URL is in environment, POSTs the message to that URL.

  • if OASIS_WEBSOCKET_URL and OASIS_WEBSOCKET_PORT are in environment, sends a websocket message.

  • if neither is configured, or all configured targets fail, no message gets through.

Else, a message sent to OASIS_SOCKET_SERVER_IP OASIS_SOCKET_SERVER_PORT defaulted to 127.0.0.1 8888.

If data contains a port_override key, that port is used in place of the default/env-var port when connecting to the socket server. The key is stripped before the message is sent.

For a specific target, use oasis_ping_http, oasis_ping_socket or oasis_ping_websocket directly.

Parameters:

data (dict) – dictionary of data: JSON serialisable

Returns:

whether attempted call gets through

Return type:

Boolean

oasislmf.utils.ping.oasis_ping_async(data)[source]

Sends a ping without blocking the caller.

oasis_ping makes a network call (HTTP POST or websocket connect) that can block for up to the configured timeout when the target is unreachable but not actively refusing the connection (wrong hostname, dropped packets, a NetworkPolicy). Calling it directly from a per-event progress ping inside a compute loop means a broken ping target stalls the calculation itself. This runs oasis_ping on a background daemon thread instead, so a stuck ping can never block the caller.

Only one ping is ever in flight at a time per process: if a previous call is still pending when this is invoked, the new update is dropped (a subsequent ping will carry a more up to date events_complete) rather than letting a persistently broken target pile up threads.

Parameters:

data (dict) – dictionary of data: JSON serialisable

oasislmf.utils.ping.oasis_ping_socket(target, data)[source]

Sends a JSON message to a target socket

Parameters:
  • target ((str, int)) – IP and port to hit

  • data (str) – JSON dumped string

Returns:

whether attempted call gets through

Return type:

Boolean

oasislmf.utils.ping.oasis_ping_http(url, data)[source]

Sends a JSON message to a target HTTP endpoint via POST.

Parameters:
Returns:

whether attempted call gets through

Return type:

Boolean

oasislmf.utils.ping.oasis_ping_websocket(ws_url, data)[source]

Sends a JSON message to a target websocket

Parameters:
  • ws_url (str) – URL to hit (e.g. “ws://oasis-websocket:8001/ws/analysis-status/”)

  • data (str) – JSON dumped string

Returns:

whether attempted call gets through

Return type:

Boolean