stateful_worker

stick_ray.stateful_worker

Module Contents

exception StatefulSessionNotFound[source]

Bases: Exception

Exception raised when a session id is not found.

Initialize self. See help(type(self)) for accurate signature.

class StatefulWorker(worker_id, **kwargs)[source]

Represents a stateful worker. Handles sessions for sticky connections, and sends heart beats to router.

Parameters:

worker_id (str) –

async ferry(method, data_ref_tuple, session_id)[source]

Ferries a method to this worker, and returns as a task, i.e. an awaitable result.

Parameters:
  • method (str) – method name to ferry

  • data_ref_tuple (Tuple[ray.ObjectRef]) – an object ref of tuple (args, kwargs)

  • session_id (str) – session id to ferry to

Returns:

the result of the operation, i.e. the task is awaited.

Raises:
  • StatefulSessionNotFound if session_id not currently managed, i.e. expired session or it never existed.

  • ValueError if session_id is found in the kwargs, as this results in an overwrite.

Return type:

Any

async get_session_state(session_id)[source]

Get the session state for a session id.

Parameters:

session_id (str) – session id to get state for

Returns:

the session state

Raises:

AttributeError if it's not found.

Return type:

Any

async set_session_state(session_id, session_state)[source]

Set the session state for the session id.

Parameters:
  • session_id (str) – session id

  • session_state (Any) – a state object.

async close_session(*, session_id)[source]

Closes the session for a given session id.

Parameters:

session_id (str) – sessoin id to close down.

async create_session(session_id)[source]

Creates a session for the given session id.

Parameters:

session_id (str) – session id, e.g. a user UUID.

Returns:

True iff session what successfully created, False

Return type:

bool

async start()[source]

Starts the worker.

async shutdown()[source]

Shuts down the worker.

async check_session(session_id)[source]

Checks if the given session id is managed by the worker.

Parameters:

session_id (str) – session id to check

Returns:

true if managed

Return type:

bool

async get_session_ids()[source]

Gets all current managed session ids.

Returns:

a set of session ids.

Return type:

Set[str]

async health_check()[source]

Simply returns, acting as a health check.