orangeqs.juice.task_manager._reservations#

Reservations of the serial slot of a service, held for proxy kernel cells.

Module Contents#

Classes#

SlotReservations

Let a proxy kernel hold the serial slot of a service while a cell runs.

Functions#

cell_display_name

Return the dashboard name of a reservation that runs cell_count cells.

Data#

CELL_TASK_TYPE

Task type that the dashboard shows for a proxy kernel cell.

API#

orangeqs.juice.task_manager._reservations.CELL_TASK_TYPE#

‘PythonCell’

Task type that the dashboard shows for a proxy kernel cell.

orangeqs.juice.task_manager._reservations.cell_display_name(cell_count: int) → str#

Return the dashboard name of a reservation that runs cell_count cells.

The name is "Python cell" for one cell, and "Python cells (3)" for three cells.

class orangeqs.juice.task_manager._reservations.SlotReservations(service_task_lock: orangeqs.juice.task_manager._scheduler.ServiceTaskLock, *, emit: collections.abc.Callable[[orangeqs.juice.task_manager._schemas.TaskEvent], None], is_kernel_idle: collections.abc.Callable[[str], bool], lease_timeout: float = 30.0, idle_timeout: float = 10.0, check_interval: float = 5.0, now_fn: collections.abc.Callable[[], float] = time.monotonic)#

Let a proxy kernel hold the serial slot of a service while a cell runs.

A proxy kernel sends cells to the service kernel without changes. Before it sends a cell, it reserves the slot of the service. Thus no task runs on the service while the cell runs. Cells that the proxy gets while a cell runs use the same reservation (see renew). When no cells are left, the proxy releases the slot.

Each reservation shows as one task on the dashboard.

While a cell runs, the proxy renews its reservation (see renew). If a proxy stops and does not release its slot, the watchdog releases the slot when both of these are true:

  • The proxy did not renew the reservation for lease_timeout seconds.

  • The kernel monitor reported the service kernel as idle for idle_timeout seconds. A status such as connecting or unknown does not count as idle, because a cell can still run.

Thus a cell that runs for a long time keeps its slot, also when the kernel monitor does not know the status. And a cell that continues in the service after its proxy stopped keeps the slot until the cell is done.

Parameters#

  • service_task_lock: The serial slots of the services. The router and the scheduler use the same lock.

  • emit: Callback that writes and publishes a task event.

  • is_kernel_idle: Callback that tells if the kernel of a service is known to be idle now.

  • lease_timeout: Seconds without a renewal after which the watchdog thinks that the proxy stopped.

  • idle_timeout: Seconds that a kernel must be idle before the watchdog releases a slot. The lease shows that the proxy stopped, so this only has to show that its last cell is done. It is longer than check_interval, so that one idle sample between two cells does not release the slot.

  • check_interval: Seconds between two passes of the watchdog.

  • now_fn: Monotonic clock. Tests can replace it.

async reserve(reservation_id: str, service: str, submitted_by: str | None) → bool#

Wait for the slot of service and hold it until it is released.

Parameters#

  • reservation_id: Unique id of the reservation. The dashboard uses it as the task id.

  • service: The service to reserve.

  • submitted_by: Identity of the user that reserves the service, for the dashboard.

Returns#

  • (bool): True if the slot is held. False if the reservation was released before it got the slot.

renew(reservation_id: str, cell_count: int | None = None) → bool#

Tell the watchdog that the proxy of a held reservation still runs.

Parameters#

  • reservation_id: The id of the reservation.

  • cell_count: Number of cells that ran with the reservation. If it changed, for example with the next cell of Run All, the name on the dashboard changes.

Returns#

  • (bool): False if the reservation is not known or does not hold the slot.

release(reservation_id: str) → bool#

Release a reservation, or cancel it if it still waits for the slot.

Returns#

  • (bool): False if the reservation is not known, for example because the watchdog released it already.

check_idle() → None#

Release each held slot whose proxy stopped and whose kernel is idle.

async run() → None#

Run the watchdog until cancelled.