gyoza.models#
gyoza domain models.
Single source of truth for all shared domain types, aggregates, and value objects used by the server, worker, and CLI.
- class gyoza.models.Constraints(cpu=None, ram_mb=None, vram_mb=None, gpu_id=None)[source]#
Bases:
objectHardware requirements for execution.
- Parameters:
- class gyoza.models.EventDelivery(topic='', attributes=<factory>)[source]#
Bases:
objectEvent delivery configuration for op runs.
- Parameters:
- class gyoza.models.EventEntry(t, type, msg, payload=<factory>)[source]#
Bases:
objectA single event in the op run timeline.
- Parameters:
- class gyoza.models.EventType(*values)[source]#
-
Event types emitted during an op run.
- ASSIGNED = 'ASSIGNED'#
- STARTED = 'STARTED'#
- INFO = 'INFO'#
- PROGRESS = 'PROGRESS'#
- COMPLETED = 'COMPLETED'#
- FAILED = 'FAILED'#
- CANCELLED = 'CANCELLED'#
- ERROR = 'ERROR'#
- RETRIED = 'RETRIED'#
- class gyoza.models.ExecutionSummary(duration_ms=None, worker_id=None, error_message=None, gpu_id=None)[source]#
Bases:
objectHigh-level execution metadata attached to a completed op run.
- Parameters:
- class gyoza.models.InputSpec(type, required=True, default=None)[source]#
Bases:
objectSpecification for a single input parameter.
- Parameters:
- class gyoza.models.InputSpecs(specs=<factory>)[source]#
Bases:
objectCollection of input specifications keyed by parameter name.
- classmethod from_dict(data)[source]#
Deserialise from a dictionary.
- exception gyoza.models.InputValidationError(errors)[source]#
Bases:
ExceptionRaised when input validation fails against an OpDefinition’s specs.
- class gyoza.models.OpAttempt(id, op_run_id, attempt, state, progress=0, events=<factory>, inputs=<factory>, outputs=<factory>, execution_summary=<factory>, constraints=<factory>, started_at=None, finished_at=None)[source]#
Bases:
objectA single execution attempt belonging to an OpRun.
OpRuns can have multiple attempts when retries are configured. Each attempt has its own event timeline, outputs, and execution summary.
- Parameters:
id (
str) – Unique identifier for the attempt (<run_id>_att_<n>).op_run_id (
str) – Parent OpRun identifier.attempt (
int) – Attempt number (1-indexed).state (
OpRunState) – Current state of this attempt.progress (
int) – Completion percentage (0–100).events (
list[EventEntry]) – Timeline of events during this attempt.inputs (
dict[str,Any]) – Snapshot of inputs at execution time.outputs (
dict[str,Any]) – Outputs produced by this attempt.execution_summary (
ExecutionSummary) – Execution metadata (worker, duration, GPU, error).constraints (
Constraints) – Hardware constraints snapshot for this attempt.
- state: OpRunState#
- events: list[EventEntry]#
- execution_summary: ExecutionSummary#
- constraints: Constraints#
- class gyoza.models.OpDefinition(id, version, image, input_specs=<factory>, output_specs=<factory>, constraints=<factory>, retry_policy=<factory>, event_delivery=<factory>, created_at=<factory>, updated_at=<factory>)[source]#
Bases:
objectAggregate root describing an operation and its execution requirements.
Serves as the template from which op runs are created. Holds the full lifecycle of a definition: creation, input validation, defaults, and updates.
- Parameters:
id (
str) – Unique human-readable identifier (e.g."sugarcane_lines_product").version (
str) – Semantic version string (e.g."1.2.0").image (
str) – Docker image reference including registry and tag.input_specs (
InputSpecs) – Accepted input parameters.output_specs (
OutputSpecs) – Output fields produced by the operation.constraints (
Constraints) – Hardware requirements for execution.retry_policy (
RetryPolicy) – Failure recovery rules.event_delivery (
EventDelivery) – Event delivery configuration for runs of this definition.created_at (
datetime) – Timestamp when the definition was registered.updated_at (
datetime) – Timestamp of the most recent update.
- input_specs: InputSpecs#
- output_specs: OutputSpecs#
- constraints: Constraints#
- retry_policy: RetryPolicy#
- event_delivery: EventDelivery#
- classmethod create(id, version, image, input_specs=None, output_specs=None, constraints=None, retry_policy=None, event_delivery=None)[source]#
Create a new OpDefinition with auto-set timestamps.
- Parameters:
id (
str) – Unique human-readable identifier.version (
str) – Semantic version of the definition.image (
str) – Docker image reference.input_specs (
InputSpecs|dict[str,Any] |None) – Accepted input parameters.output_specs (
OutputSpecs|dict[str,Any] |None) – Output field definitions.constraints (
Constraints|None) – Hardware requirements.retry_policy (
RetryPolicy|None) – Failure recovery rules.event_delivery (
EventDelivery|None) – Event delivery configuration.
- Returns:
A new OpDefinition instance with timestamps set to now.
- Return type:
- validate_inputs(inputs)[source]#
Validate inputs against the definition’s input specs.
- Parameters:
- Raises:
InputValidationError – If required inputs are missing.
- Return type:
- update(version=None, image=None, input_specs=None, output_specs=None, constraints=None, retry_policy=None)[source]#
Update definition fields in place.
- Parameters:
input_specs (
InputSpecs|dict[str,Any] |None) – New input specifications.output_specs (
OutputSpecs|dict[str,Any] |None) – New output specifications.constraints (
Constraints|None) – New hardware requirements.retry_policy (
RetryPolicy|None) – New retry policy.
- Return type:
- class gyoza.models.OpRun(id, state, priority, image, inputs=<factory>, constraints=<factory>, retry_policy=<factory>, event_delivery=<factory>, op_definition=None, created_at=<factory>, updated_at=<factory>, _attempts=<factory>, _current_attempt_index=-1)[source]#
Bases:
objectAggregate root for execution runs.
Encapsulates all attempts internally. Users interact only with OpRun; the current attempt’s data (progress, events, outputs, execution_summary) is exposed directly via properties.
A new OpRun always starts with its first attempt. Additional attempts are created by
RETRIED(including afterrelease_assignment()) or automatic retry afterFAILEDwhen policy allows.- Parameters:
id (
str) – Unique identifier for the run.state (
OpRunState) – Current state of the run.priority (
int) – Execution queue priority.image (
str) – Docker image reference.constraints (
Constraints) – Hardware requirements.retry_policy (
RetryPolicy) – Failure recovery rules.event_delivery (
EventDelivery) – Event delivery configuration.op_definition (
str|None) – Parent OpDefinition name (Nonefor ad-hoc runs).created_at (
datetime) – When the run was created.updated_at (
datetime) – Last state update timestamp._current_attempt_index (int)
- state: OpRunState#
- constraints: Constraints#
- retry_policy: RetryPolicy#
- event_delivery: EventDelivery#
- classmethod create(image, priority=0, inputs=None, constraints=None, retry_policy=None, event_delivery=None, op_definition=None)[source]#
Create a new OpRun in PENDING state with its first attempt.
- Parameters:
image (
str) – Docker image reference.priority (
int) – Scheduling priority (default 0).constraints (
Constraints|None) – Hardware requirements.retry_policy (
RetryPolicy|None) – Failure recovery rules.event_delivery (
EventDelivery|None) – Event delivery configuration.
- Returns:
A new OpRun in PENDING state with its first attempt created.
- Return type:
- property events: list[EventEntry]#
Event timeline from the current attempt.
- property execution_summary: ExecutionSummary#
Execution metadata from the current attempt.
- set_state(new_state)[source]#
Update the run state directly.
- Parameters:
new_state (
OpRunState) – New state to apply.- Return type:
- assign(worker_id, gpu_id=None)[source]#
Allocate this run to a worker (scheduler / internal).
Emits an
ASSIGNEDevent and transitions PENDING → ASSIGNED.- Parameters:
- Raises:
ValueError – If the run is not PENDING.
OpRunLockedException – If the run is terminal.
- Return type:
- release_assignment()[source]#
Reclaim a run whose worker is gone (reaper / internal).
Validates ASSIGNED or RUNNING, then emits
RETRIEDwithforceso a fresh attempt is started without enforcingmax_attempts.- Raises:
ValueError – If the run is not ASSIGNED or RUNNING.
OpRunLockedException – If the run is terminal.
- Return type:
- add_event(event_type, msg, payload=None)[source]#
Append an event to the current attempt and react to its type.
Lifecycle transitions are implemented in
gyoza.models.op_run_events. Notable types:ASSIGNED: PENDING → ASSIGNED (requiresworker_idin payload)STARTED: ASSIGNED → RUNNINGPROGRESS: updates progress (msg must be 0–100)COMPLETED: terminal COMPLETEDFAILED: terminal FAILED; if retries remain, appendsRETRIEDand starts a new attempt (PENDING)CANCELLED: terminal CANCELLEDRETRIED: records retry on the current attempt, and create a new attempt
- Parameters:
- Raises:
OpRunLockedException – If the run is already in a terminal state (except for
RETRIED).ValueError – If a required payload is missing or the event is invalid in the current state.
- Return type:
- can_retry()[source]#
Return True if another attempt is allowed.
- Returns:
True when current attempt count is below max_attempts.
- Return type:
- exception gyoza.models.OpRunLockedException[source]#
Bases:
ExceptionRaised when trying to modify a terminal-state OpRun.
- class gyoza.models.OpRunState(*values)[source]#
-
Lifecycle states for an op run.
- PENDING = 'PENDING'#
- ASSIGNED = 'ASSIGNED'#
- RUNNING = 'RUNNING'#
- COMPLETED = 'COMPLETED'#
- FAILED = 'FAILED'#
- CANCELLED = 'CANCELLED'#
- class gyoza.models.OutputSpec(type)[source]#
Bases:
objectSpecification for a single output field.
- Parameters:
type (
str) – Type name of the output (e.g."string","float").
- class gyoza.models.OutputSpecs(specs=<factory>)[source]#
Bases:
objectCollection of output specifications keyed by field name.
- Parameters:
specs (
dict[str,OutputSpec]) – Mapping of output field names to their specifications.
- specs: dict[str, OutputSpec]#
- class gyoza.models.RetryPolicy(max_attempts=1)[source]#
Bases:
objectRules for automatic failure recovery.
Only applies to automatic retries when a FAILED event is received. The retry API endpoint ignores max_attempts and always allows a retry.
- Parameters:
max_attempts (
int) – Maximum number of execution attempts (including the first). When a run fails, it is retried immediately if attempts remain.
OpDefinition aggregate and input/output specification types.
- exception gyoza.models.op_definition.InputValidationError(errors)[source]#
Bases:
ExceptionRaised when input validation fails against an OpDefinition’s specs.
- class gyoza.models.op_definition.InputSpec(type, required=True, default=None)[source]#
Bases:
objectSpecification for a single input parameter.
- Parameters:
- class gyoza.models.op_definition.InputSpecs(specs=<factory>)[source]#
Bases:
objectCollection of input specifications keyed by parameter name.
- classmethod from_dict(data)[source]#
Deserialise from a dictionary.
- class gyoza.models.op_definition.OutputSpec(type)[source]#
Bases:
objectSpecification for a single output field.
- Parameters:
type (
str) – Type name of the output (e.g."string","float").
- class gyoza.models.op_definition.OutputSpecs(specs=<factory>)[source]#
Bases:
objectCollection of output specifications keyed by field name.
- Parameters:
specs (
dict[str,OutputSpec]) – Mapping of output field names to their specifications.
- specs: dict[str, OutputSpec]#
- class gyoza.models.op_definition.OpDefinition(id, version, image, input_specs=<factory>, output_specs=<factory>, constraints=<factory>, retry_policy=<factory>, event_delivery=<factory>, created_at=<factory>, updated_at=<factory>)[source]#
Bases:
objectAggregate root describing an operation and its execution requirements.
Serves as the template from which op runs are created. Holds the full lifecycle of a definition: creation, input validation, defaults, and updates.
- Parameters:
id (
str) – Unique human-readable identifier (e.g."sugarcane_lines_product").version (
str) – Semantic version string (e.g."1.2.0").image (
str) – Docker image reference including registry and tag.input_specs (
InputSpecs) – Accepted input parameters.output_specs (
OutputSpecs) – Output fields produced by the operation.constraints (
Constraints) – Hardware requirements for execution.retry_policy (
RetryPolicy) – Failure recovery rules.event_delivery (
EventDelivery) – Event delivery configuration for runs of this definition.created_at (
datetime) – Timestamp when the definition was registered.updated_at (
datetime) – Timestamp of the most recent update.
- input_specs: InputSpecs#
- output_specs: OutputSpecs#
- constraints: Constraints#
- retry_policy: RetryPolicy#
- event_delivery: EventDelivery#
- classmethod create(id, version, image, input_specs=None, output_specs=None, constraints=None, retry_policy=None, event_delivery=None)[source]#
Create a new OpDefinition with auto-set timestamps.
- Parameters:
id (
str) – Unique human-readable identifier.version (
str) – Semantic version of the definition.image (
str) – Docker image reference.input_specs (
InputSpecs|dict[str,Any] |None) – Accepted input parameters.output_specs (
OutputSpecs|dict[str,Any] |None) – Output field definitions.constraints (
Constraints|None) – Hardware requirements.retry_policy (
RetryPolicy|None) – Failure recovery rules.event_delivery (
EventDelivery|None) – Event delivery configuration.
- Returns:
A new OpDefinition instance with timestamps set to now.
- Return type:
- validate_inputs(inputs)[source]#
Validate inputs against the definition’s input specs.
- Parameters:
- Raises:
InputValidationError – If required inputs are missing.
- Return type:
- update(version=None, image=None, input_specs=None, output_specs=None, constraints=None, retry_policy=None)[source]#
Update definition fields in place.
- Parameters:
input_specs (
InputSpecs|dict[str,Any] |None) – New input specifications.output_specs (
OutputSpecs|dict[str,Any] |None) – New output specifications.constraints (
Constraints|None) – New hardware requirements.retry_policy (
RetryPolicy|None) – New retry policy.
- Return type:
OpRun aggregate root — execution run lifecycle management.
- exception gyoza.models.op_run.OpRunLockedException[source]#
Bases:
ExceptionRaised when trying to modify a terminal-state OpRun.
- class gyoza.models.op_run.OpRun(id, state, priority, image, inputs=<factory>, constraints=<factory>, retry_policy=<factory>, event_delivery=<factory>, op_definition=None, created_at=<factory>, updated_at=<factory>, _attempts=<factory>, _current_attempt_index=-1)[source]#
Bases:
objectAggregate root for execution runs.
Encapsulates all attempts internally. Users interact only with OpRun; the current attempt’s data (progress, events, outputs, execution_summary) is exposed directly via properties.
A new OpRun always starts with its first attempt. Additional attempts are created by
RETRIED(including afterrelease_assignment()) or automatic retry afterFAILEDwhen policy allows.- Parameters:
id (
str) – Unique identifier for the run.state (
OpRunState) – Current state of the run.priority (
int) – Execution queue priority.image (
str) – Docker image reference.constraints (
Constraints) – Hardware requirements.retry_policy (
RetryPolicy) – Failure recovery rules.event_delivery (
EventDelivery) – Event delivery configuration.op_definition (
str|None) – Parent OpDefinition name (Nonefor ad-hoc runs).created_at (
datetime) – When the run was created.updated_at (
datetime) – Last state update timestamp._current_attempt_index (int)
- state: OpRunState#
- constraints: Constraints#
- retry_policy: RetryPolicy#
- event_delivery: EventDelivery#
- classmethod create(image, priority=0, inputs=None, constraints=None, retry_policy=None, event_delivery=None, op_definition=None)[source]#
Create a new OpRun in PENDING state with its first attempt.
- Parameters:
image (
str) – Docker image reference.priority (
int) – Scheduling priority (default 0).constraints (
Constraints|None) – Hardware requirements.retry_policy (
RetryPolicy|None) – Failure recovery rules.event_delivery (
EventDelivery|None) – Event delivery configuration.
- Returns:
A new OpRun in PENDING state with its first attempt created.
- Return type:
- property events: list[EventEntry]#
Event timeline from the current attempt.
- property execution_summary: ExecutionSummary#
Execution metadata from the current attempt.
- set_state(new_state)[source]#
Update the run state directly.
- Parameters:
new_state (
OpRunState) – New state to apply.- Return type:
- assign(worker_id, gpu_id=None)[source]#
Allocate this run to a worker (scheduler / internal).
Emits an
ASSIGNEDevent and transitions PENDING → ASSIGNED.- Parameters:
- Raises:
ValueError – If the run is not PENDING.
OpRunLockedException – If the run is terminal.
- Return type:
- release_assignment()[source]#
Reclaim a run whose worker is gone (reaper / internal).
Validates ASSIGNED or RUNNING, then emits
RETRIEDwithforceso a fresh attempt is started without enforcingmax_attempts.- Raises:
ValueError – If the run is not ASSIGNED or RUNNING.
OpRunLockedException – If the run is terminal.
- Return type:
- add_event(event_type, msg, payload=None)[source]#
Append an event to the current attempt and react to its type.
Lifecycle transitions are implemented in
gyoza.models.op_run_events. Notable types:ASSIGNED: PENDING → ASSIGNED (requiresworker_idin payload)STARTED: ASSIGNED → RUNNINGPROGRESS: updates progress (msg must be 0–100)COMPLETED: terminal COMPLETEDFAILED: terminal FAILED; if retries remain, appendsRETRIEDand starts a new attempt (PENDING)CANCELLED: terminal CANCELLEDRETRIED: records retry on the current attempt, and create a new attempt
- Parameters:
- Raises:
OpRunLockedException – If the run is already in a terminal state (except for
RETRIED).ValueError – If a required payload is missing or the event is invalid in the current state.
- Return type:
- can_retry()[source]#
Return True if another attempt is allowed.
- Returns:
True when current attempt count is below max_attempts.
- Return type:
OpAttempt entity — a single execution attempt within an OpRun.
- class gyoza.models.op_attempt.OpAttempt(id, op_run_id, attempt, state, progress=0, events=<factory>, inputs=<factory>, outputs=<factory>, execution_summary=<factory>, constraints=<factory>, started_at=None, finished_at=None)[source]#
Bases:
objectA single execution attempt belonging to an OpRun.
OpRuns can have multiple attempts when retries are configured. Each attempt has its own event timeline, outputs, and execution summary.
- Parameters:
id (
str) – Unique identifier for the attempt (<run_id>_att_<n>).op_run_id (
str) – Parent OpRun identifier.attempt (
int) – Attempt number (1-indexed).state (
OpRunState) – Current state of this attempt.progress (
int) – Completion percentage (0–100).events (
list[EventEntry]) – Timeline of events during this attempt.inputs (
dict[str,Any]) – Snapshot of inputs at execution time.outputs (
dict[str,Any]) – Outputs produced by this attempt.execution_summary (
ExecutionSummary) – Execution metadata (worker, duration, GPU, error).constraints (
Constraints) – Hardware constraints snapshot for this attempt.
- state: OpRunState#
- events: list[EventEntry]#
- execution_summary: ExecutionSummary#
- constraints: Constraints#
Shared value objects for the gyoza domain.
Contains hardware requirements, policy types, op run states, event types, and execution metadata — all pure data structures with no dependencies on other model files, making them safe to import from anywhere.
- class gyoza.models.resources.Constraints(cpu=None, ram_mb=None, vram_mb=None, gpu_id=None)[source]#
Bases:
objectHardware requirements for execution.
- Parameters:
- class gyoza.models.resources.RetryPolicy(max_attempts=1)[source]#
Bases:
objectRules for automatic failure recovery.
Only applies to automatic retries when a FAILED event is received. The retry API endpoint ignores max_attempts and always allows a retry.
- Parameters:
max_attempts (
int) – Maximum number of execution attempts (including the first). When a run fails, it is retried immediately if attempts remain.
- class gyoza.models.resources.EventDelivery(topic='', attributes=<factory>)[source]#
Bases:
objectEvent delivery configuration for op runs.
- Parameters:
- class gyoza.models.resources.OpRunState(*values)[source]#
-
Lifecycle states for an op run.
- PENDING = 'PENDING'#
- ASSIGNED = 'ASSIGNED'#
- RUNNING = 'RUNNING'#
- COMPLETED = 'COMPLETED'#
- FAILED = 'FAILED'#
- CANCELLED = 'CANCELLED'#
- class gyoza.models.resources.EventType(*values)[source]#
-
Event types emitted during an op run.
- ASSIGNED = 'ASSIGNED'#
- STARTED = 'STARTED'#
- INFO = 'INFO'#
- PROGRESS = 'PROGRESS'#
- COMPLETED = 'COMPLETED'#
- FAILED = 'FAILED'#
- CANCELLED = 'CANCELLED'#
- ERROR = 'ERROR'#
- RETRIED = 'RETRIED'#
- class gyoza.models.resources.EventEntry(t, type, msg, payload=<factory>)[source]#
Bases:
objectA single event in the op run timeline.
- Parameters: