Source code for gyoza.server.scheduler.strategies.direct
"""Direct scheduling strategy.
Simple strategy that directly assigns the first available pending run to the worker.
"""
from gyoza.server.op_run.repository import OpRunRepository
from gyoza.server.worker import Worker, WorkerOpRun
[docs]
class DirectSchedulingStrategy:
"""Simple scheduling strategy that directly assigns pending runs.
This strategy assigns the first pending run (highest priority) directly
to the requesting worker. It's deterministic and suitable for testing.
"""
[docs]
def allocate(
self,
worker_id: str,
op_run_repo: OpRunRepository,
workers: list[Worker],
) -> list[WorkerOpRun]:
"""Select runs to allocate to the given worker.
Directly assigns the first pending run (highest priority) to the worker.
Returns empty list if no pending runs are available.
Parameters
----------
worker_id : str
ID of the worker requesting work.
op_run_repo : OpRunRepository
Repository for querying OpRuns.
workers : list[Worker]
List of all active workers (unused in this strategy).
Returns
-------
list[WorkerOpRun]
First pending Op run, or empty list if none available.
"""
pending_runs = op_run_repo.list_pending_ordered()
if not pending_runs:
return []
# Return the first (highest priority) pending run
return [WorkerOpRun.from_op_run(pending_runs[0])]