schedr.runner.protocol

The agent <-> runner channel: length-prefixed JSON over a Unix socket.

Each message is a 4-byte big-endian length followed by that many bytes of UTF-8 JSON, an object tagged by type (the shapes are schema/runner.schema.json, generated from schedr-model, runner.rs).

schedr.runner.protocol.MAX_MESSAGE_SIZE = 67108864

The largest message either side accepts, in bytes (as in schedr-model).

class schedr.runner.protocol.Asking(*args, **kwargs)

Bases: Protocol

What a task needs of the channel: a task’s whole channel, or a watcher’s part of a host’s.

ask(message)

Sends a request and receives its answer.

Parameters:

message (dict[str, Any])

Return type:

dict[str, Any]

send(message)

Sends one message.

Parameters:

message (dict[str, Any])

Return type:

None

exception schedr.runner.protocol.ProtocolError

Bases: Exception

The other side closed the connection or sent something that isn’t a valid message.

exception schedr.runner.protocol.ChannelClosedError

Bases: ProtocolError

The other side closed the connection between messages (the fork server’s way to stop).

class schedr.runner.protocol.Channel(sock)

Bases: object

One end of the channel, over a connected socket.

Parameters:

sock (socket)

ask(message)

Sends a request and receives its answer, one request at a time on this channel.

A task’s threads may read secrets and open connections at once: each answer goes to the thread that asked.

Parameters:

message (dict[str, Any]) – The request.

Returns:

The answer.

Return type:

dict[str, Any]

send(message)

Sends one message.

Parameters:

message (dict[str, Any]) – A JSON object with a type.

Raises:

ProtocolError – If the encoded message is over MAX_MESSAGE_SIZE.

Return type:

None

receive()

Receives one message.

Returns:

The message, a JSON object with a string type.

Raises:
  • ChannelClosedError – If the connection closed before the message.

  • ProtocolError – If the connection closed within it, the size is over the limit, or the body isn’t a JSON object with a type.

Return type:

dict[str, Any]

receive_with_fds(max_fds)

Receives one message and the descriptors sent with it (SCM_RIGHTS).

Parameters:

max_fds (int) – The most descriptors accepted.

Returns:

The message and the received descriptors, which the caller owns.

Raises:
Return type:

tuple[dict[str, Any], list[int]]

settimeout(seconds)

Sets how long a send or a receive may wait.

Parameters:

seconds (float | None) – The time; None: no limit.

Return type:

None

close()

Closes the socket.

Return type:

None

schedr.runner.protocol.from_fd(fd)

The channel on the socket the agent handed over (SCHEDR_AGENT_FD).

The descriptor is made blocking (Python’s socket would think it is, and a non-blocking one would fail its reads), and non-inheritable, so processes the task starts don’t get it.

Parameters:

fd (int) – The inherited descriptor of the runner’s end of the agent’s socket pair.

Returns:

The channel.

Raises:

OSError – If the descriptor isn’t an open socket.

Return type:

Channel