Workflow State¶
Manager for interacting with observation workflow state resources.
- class gpp_client.managers.workflow_state.WorkflowStateManager(client: GPPClient)[source]¶
Bases:
BaseManagerManager for interacting with observation workflow state resources.
- async get_by_id(*, observation_id: str | None = None, observation_reference: str | None = None) dict[str, Any][source]¶
Get the workflow state and calculation state of an observation by its ID or reference.
- Parameters:
- Returns:
The returned workflow state for the observation.
- Return type:
- Raises:
GPPValidationError – If neither or both of
observation_idandobservation_referenceare provided.GPPClientError – If neither or both of
observation_idandobservation_referenceare provided, or if the observation cannot be found.
- get_result(result: dict[str, Any] | None, operation_name: str | None = None) dict[str, Any]¶
Extract the payload for a given GraphQL operation.
- Parameters:
- Returns:
The extracted payload for the specified operation.
- Return type:
- Raises:
GPPClientError – If the result is empty or invalid, or if the specified operation name is not found in the result.
- get_single_result(payload: dict[str, Any], key: str) dict[str, Any]¶
Extract exactly one item from a list-valued field in a GraphQL payload.
- Parameters:
- Returns:
The single item extracted from the field.
- Return type:
- Raises:
GPPClientError – If the specified field is missing from the payload, is not a list, or does not contain exactly one item.
- load_properties(*, properties: Any | None, from_json: str | Path | dict[str, Any] | None, cls: type[T]) T¶
Return a validated properties object from exactly one data source.
- Parameters:
- Returns:
Instance of
clsrepresenting the validated properties.- Return type:
T
- Raises:
GPPValidationError – If validation fails or an error occurs loading the properties.
- raise_error(exc_class: type[GPPError], exc: Exception, *, include_traceback: bool = False) NoReturn¶
Raise a structured exception with contextual information.
- async raise_for_status(response, *, ok_statuses: set[int], default_message: str = 'Request failed') None¶
Raise an exception if the HTTP response status is not OK.
- Parameters:
- Raises:
GPPResponseError – If the response status is not in
ok_statuses.
- resolve_content(*, file_path: str | Path | None, content: bytes | None) bytes¶
Resolve upload content bytes from exactly one source.
- Parameters:
- Returns:
The resolved content bytes.
- Return type:
- Raises:
GPPValidationError – If both or neither of
file_pathandcontentare provided, or iffile_pathis invalid.GPPClientError – If reading the file fails due to an unexpected I/O error.
- async update_by_id(*, workflow_state: ObservationWorkflowState, observation_id: str) dict[str, Any][source]¶
Update the workflow state of an observation by its ID, or return the current workflow if already set.
- This function will:
Fetch the current observation and its workflow.
If the calculation state is not
READY, raise an error to retry later.If the desired state is already set, return the workflow as-is.
Otherwise, validate the requested workflow state against
validTransitions.If valid, submit the mutation to update the workflow state.
- Parameters:
workflow_state (ObservationWorkflowState) – The desired workflow state to transition to.
observation_id (str) – The observation ID.
- Returns:
The returned workflow state for the observation.
- Return type:
- Raises:
GPPClientError – If there are general client-side errors.
GPPValidationError – If the requested workflow state transition is invalid.
GPPRetryableError – If the observation calculation is not
READY.
- async update_by_id_with_retry(*, workflow_state: ObservationWorkflowState, observation_id: str, max_attempts: int = 10, initial_delay: float = 0.0, retry_delay: float = 1.0) dict[str, Any][source]¶
Update the workflow state of an observation by its ID, retrying if the observation is not ready.
This function wraps
update_by_idwith retry logic to handle cases where the observation calculation is not yet in theREADYstate.- Parameters:
workflow_state (ObservationWorkflowState) – The desired workflow state to transition to.
observation_id (str) – The observation ID.
max_attempts (int, default=10) – Maximum number of retry attempts.
initial_delay (float, default=0.0) – Initial delay in seconds before first attempt.
retry_delay (float, default=1.0) – Delay in seconds between retry attempts.
- Returns:
The returned workflow state for the observation.
- Return type:
- Raises:
GPPClientError – If the maximum number of retry attempts is exceeded without success.
GPPValidationError – If the requested workflow state transition is invalid.
- validate_single_identifier(**kwargs) None¶
Validate that exactly one identifier is provided.
This helper checks that exactly one of the provided keyword arguments is non-None. It raises a ValueError otherwise.
- Parameters:
**kwargs (dict[str, Optional[str]]) – A dictionary of identifier keyword arguments to validate.
- Raises:
GPPValidationError – If none or more than one identifiers are provided.