gpp-client 26.11.3.dev2__tar.gz → 26.11.3.dev3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/PKG-INFO +1 -1
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/base.py +5 -2
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/workflow_state.py +105 -15
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/exceptions.py +53 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/__init__.py +308 -726
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/client.py +563 -1318
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/custom_fields.py +40 -1
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/custom_mutations.py +26 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/custom_typing_fields.py +6 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/enums.py +1 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/fragments.py +978 -0
- gpp_client-26.11.3.dev3/src/gpp_client/generated/get_goats_config_options.py +24 -0
- gpp_client-26.11.3.dev3/src/gpp_client/generated/get_goats_configuration_requests.py +25 -0
- gpp_client-26.11.3.dev3/src/gpp_client/generated/get_goats_observations.py +21 -0
- gpp_client-26.11.3.dev3/src/gpp_client/generated/get_goats_programs.py +21 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_observation_workflow_state_by_id.py +6 -1
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_observation_workflow_state_by_reference.py +6 -1
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/input_types.py +12 -0
- gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_config_options.py +0 -119
- gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_configuration_requests.py +0 -209
- gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_observations.py +0 -2807
- gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_programs.py +0 -49
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/.gitignore +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/LICENSE +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/README.md +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/graphql/README.md +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/pyproject.toml +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/__init__.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/__init__.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/cli.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/__init__.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/attachment.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/goats.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/observation.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/program.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/scheduler.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/site_status.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/target.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/commands/workflow_state.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/console.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/output.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/cli/utils.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/client.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/constants.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/__init__.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/atom.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/attachment.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/goats.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/observation.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/program.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/scheduler.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/site_status.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/target.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/environment.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/async_base_client.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/base_model.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/base_operation.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/clone_observation.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/clone_target.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/create_call_for_proposals.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/create_observation.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/create_program.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/create_target_by_program_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/create_target_by_program_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/create_target_by_proposal_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/custom_queries.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/delete_call_for_proposals_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/delete_observation_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/delete_observation_by_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/delete_program_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/delete_target_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/exceptions.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_call_for_proposals.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_calls_for_proposals.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_observation.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_observation_attachments_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_observation_attachments_by_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_observations.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_program_attachments_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_program_attachments_by_proposal_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_program_attachments_by_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_program_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_program_by_proposal_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_program_by_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_programs.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_scheduler_all_programs_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_scheduler_programs.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_target_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/get_targets.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/obs_calculation_update.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/observation_edit.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/package_environment.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/ping.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/program_edit.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/restore_call_for_proposals_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/restore_observation_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/restore_observation_by_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/restore_program_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/restore_target_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/scheduler_executed_events.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/scheduler_observations_updates.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/set_observation_workflow_state.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/target_edit.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_call_for_proposals_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_calls_for_proposals.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_observation_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_observation_by_reference.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_observations.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_program_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_programs.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_target_by_id.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/generated/update_targets.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/logging_utils.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/rest/__init__.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/rest/client.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/rest/models.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/rest/utils.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/settings.py +0 -0
- {gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/urls.py +0 -0
|
@@ -52,6 +52,9 @@ class BaseDomain:
|
|
|
52
52
|
"""
|
|
53
53
|
Raise a structured exception with contextual information.
|
|
54
54
|
|
|
55
|
+
The log line names the domain; the exception message does not, since
|
|
56
|
+
applications show it to their users.
|
|
57
|
+
|
|
55
58
|
Parameters
|
|
56
59
|
----------
|
|
57
60
|
exc_class : type[GPPError]
|
|
@@ -69,8 +72,8 @@ class BaseDomain:
|
|
|
69
72
|
class_name = self.__class__.__name__
|
|
70
73
|
# Fall back to the type name so an exception raised without a message
|
|
71
74
|
# does not end up as an empty error.
|
|
72
|
-
message =
|
|
73
|
-
logger.error(message, exc_info=include_traceback)
|
|
75
|
+
message = str(exc) or type(exc).__name__
|
|
76
|
+
logger.error("%s: %s", class_name, message, exc_info=include_traceback)
|
|
74
77
|
|
|
75
78
|
if include_traceback:
|
|
76
79
|
raise exc_class(message) from exc
|
{gpp_client-26.11.3.dev2 → gpp_client-26.11.3.dev3}/src/gpp_client/domains/workflow_state.py
RENAMED
|
@@ -8,10 +8,17 @@ import asyncio
|
|
|
8
8
|
import logging
|
|
9
9
|
|
|
10
10
|
from gpp_client.domains.base import BaseDomain
|
|
11
|
-
from gpp_client.exceptions import
|
|
11
|
+
from gpp_client.exceptions import (
|
|
12
|
+
GPPClientError,
|
|
13
|
+
GPPRetryableError,
|
|
14
|
+
GPPValidationError,
|
|
15
|
+
GPPWorkflowTransitionError,
|
|
16
|
+
WorkflowReason,
|
|
17
|
+
)
|
|
12
18
|
from gpp_client.generated.enums import CalculationState, ObservationWorkflowState
|
|
13
19
|
from gpp_client.generated.get_observation_workflow_state_by_id import (
|
|
14
20
|
GetObservationWorkflowStateById,
|
|
21
|
+
GetObservationWorkflowStateByIdObservation,
|
|
15
22
|
GetObservationWorkflowStateByIdObservationWorkflow,
|
|
16
23
|
)
|
|
17
24
|
from gpp_client.generated.get_observation_workflow_state_by_reference import (
|
|
@@ -105,8 +112,8 @@ class WorkflowStateDomain(BaseDomain):
|
|
|
105
112
|
------
|
|
106
113
|
GPPClientError
|
|
107
114
|
If there are general client-side errors.
|
|
108
|
-
|
|
109
|
-
If the requested
|
|
115
|
+
GPPWorkflowTransitionError
|
|
116
|
+
If GPP does not allow the requested state; it carries GPP's reasons.
|
|
110
117
|
GPPRetryableError
|
|
111
118
|
If the observation calculation is not ``READY``.
|
|
112
119
|
"""
|
|
@@ -137,11 +144,13 @@ class WorkflowStateDomain(BaseDomain):
|
|
|
137
144
|
workflow.value.model_dump(by_alias=True)
|
|
138
145
|
)
|
|
139
146
|
)
|
|
140
|
-
# Validate the requested workflow state against 'validTransitions'.
|
|
147
|
+
# Validate the requested workflow state against 'validTransitions'. The
|
|
148
|
+
# error goes out as raised, since raise_error would drop its reasons.
|
|
141
149
|
try:
|
|
142
150
|
_check_valid_transition(workflow, workflow_state)
|
|
143
|
-
except
|
|
144
|
-
|
|
151
|
+
except GPPWorkflowTransitionError as exc:
|
|
152
|
+
logger.error("%s: %s", type(self).__name__, exc)
|
|
153
|
+
raise
|
|
145
154
|
|
|
146
155
|
mutation_result = await self._graphql.set_observation_workflow_state(
|
|
147
156
|
observation_id=observation_id,
|
|
@@ -222,12 +231,66 @@ class WorkflowStateDomain(BaseDomain):
|
|
|
222
231
|
# This is the only retryable case: calculation state not READY.
|
|
223
232
|
if attempt < max_attempts:
|
|
224
233
|
await asyncio.sleep(retry_delay)
|
|
225
|
-
except (GPPValidationError, GPPClientError)
|
|
226
|
-
|
|
234
|
+
except (GPPValidationError, GPPClientError):
|
|
235
|
+
# update_by_id already logged it.
|
|
236
|
+
raise
|
|
227
237
|
|
|
228
238
|
exc = GPPClientError("Failed to set workflow state after multiple retries.")
|
|
229
239
|
self.raise_error(type(exc), exc)
|
|
230
240
|
|
|
241
|
+
async def get_by_id_when_ready(
|
|
242
|
+
self,
|
|
243
|
+
observation_id: str,
|
|
244
|
+
*,
|
|
245
|
+
max_attempts: int = 10,
|
|
246
|
+
initial_delay: float = 0.0,
|
|
247
|
+
retry_delay: float = 1.0,
|
|
248
|
+
) -> GetObservationWorkflowStateByIdObservation:
|
|
249
|
+
"""
|
|
250
|
+
Get an observation's workflow once GPP has finished calculating it.
|
|
251
|
+
|
|
252
|
+
After an edit, GPP recalculates the observation in the background, and its
|
|
253
|
+
workflow (state, valid transitions and validation errors) stays out of date
|
|
254
|
+
until the calculation state is ``READY``.
|
|
255
|
+
|
|
256
|
+
Parameters
|
|
257
|
+
----------
|
|
258
|
+
observation_id : str
|
|
259
|
+
The observation ID.
|
|
260
|
+
max_attempts : int, default=10
|
|
261
|
+
Maximum number of times to ask.
|
|
262
|
+
initial_delay : float, default=0.0
|
|
263
|
+
Delay in seconds before asking the first time.
|
|
264
|
+
retry_delay : float, default=1.0
|
|
265
|
+
Delay in seconds between asks.
|
|
266
|
+
|
|
267
|
+
Returns
|
|
268
|
+
-------
|
|
269
|
+
GetObservationWorkflowStateByIdObservation
|
|
270
|
+
The observation, with its workflow as calculated and the warnings its
|
|
271
|
+
program dismissed, which do not keep it from ``READY``.
|
|
272
|
+
|
|
273
|
+
Raises
|
|
274
|
+
------
|
|
275
|
+
GPPClientError
|
|
276
|
+
If GPP returns no such observation, or has not finished calculating it
|
|
277
|
+
after every attempt.
|
|
278
|
+
"""
|
|
279
|
+
await asyncio.sleep(initial_delay)
|
|
280
|
+
for attempt in range(1, max_attempts + 1):
|
|
281
|
+
result = await self.get_by_id(observation_id=observation_id)
|
|
282
|
+
observation = result.observation
|
|
283
|
+
if observation is None or observation.workflow is None:
|
|
284
|
+
exc = GPPClientError(f"GPP returned no workflow for {observation_id}.")
|
|
285
|
+
self.raise_error(type(exc), exc)
|
|
286
|
+
if observation.workflow.state == CalculationState.READY:
|
|
287
|
+
return observation
|
|
288
|
+
if attempt < max_attempts:
|
|
289
|
+
await asyncio.sleep(retry_delay)
|
|
290
|
+
|
|
291
|
+
exc = GPPClientError("GPP did not finish calculating the observation in time.")
|
|
292
|
+
self.raise_error(type(exc), exc)
|
|
293
|
+
|
|
231
294
|
|
|
232
295
|
def _check_ready(workflow: GetObservationWorkflowStateByIdObservationWorkflow) -> None:
|
|
233
296
|
"""
|
|
@@ -290,14 +353,41 @@ def _check_valid_transition(
|
|
|
290
353
|
|
|
291
354
|
Raises
|
|
292
355
|
------
|
|
293
|
-
|
|
356
|
+
GPPWorkflowTransitionError
|
|
294
357
|
If the requested transition is not allowed based on
|
|
295
|
-
``validTransitions``.
|
|
358
|
+
``validTransitions``. It carries GPP's validation messages, which say
|
|
359
|
+
why (for example, that no science band is selected), errors first. Its
|
|
360
|
+
message gives them too, or else the states GPP allows.
|
|
296
361
|
"""
|
|
297
362
|
valid_transitions = workflow.value.valid_transitions or []
|
|
298
|
-
if workflow_state
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
363
|
+
if workflow_state in valid_transitions:
|
|
364
|
+
return
|
|
365
|
+
|
|
366
|
+
# A code GPP sends without messages is still a reason.
|
|
367
|
+
reasons = [
|
|
368
|
+
WorkflowReason(
|
|
369
|
+
severity=error.severity.value,
|
|
370
|
+
code=error.code.value,
|
|
371
|
+
message=message,
|
|
372
|
+
)
|
|
373
|
+
for error in workflow.value.validation_errors or []
|
|
374
|
+
for message in (error.messages or [error.code.value])
|
|
375
|
+
]
|
|
376
|
+
# Errors are what keeps the state from changing, so they come first.
|
|
377
|
+
reasons.sort(key=lambda reason: reason.severity != "ERROR")
|
|
378
|
+
allowed = [t.value for t in valid_transitions]
|
|
379
|
+
|
|
380
|
+
if reasons:
|
|
381
|
+
text = " ".join(reason.message for reason in reasons)
|
|
382
|
+
message = f"Cannot change to {workflow_state.value}: {text}"
|
|
383
|
+
else:
|
|
384
|
+
message = (
|
|
385
|
+
f"Cannot change to {workflow_state.value}. "
|
|
386
|
+
f"GPP allows: {', '.join(allowed) or 'none'}."
|
|
303
387
|
)
|
|
388
|
+
raise GPPWorkflowTransitionError(
|
|
389
|
+
message,
|
|
390
|
+
requested=workflow_state.value,
|
|
391
|
+
allowed=allowed,
|
|
392
|
+
reasons=reasons,
|
|
393
|
+
)
|
|
@@ -10,9 +10,13 @@ __all__ = [
|
|
|
10
10
|
"GPPTimeoutError",
|
|
11
11
|
"GPPResponseError",
|
|
12
12
|
"GPPValidationError",
|
|
13
|
+
"GPPWorkflowTransitionError",
|
|
13
14
|
"GPPRetryableError",
|
|
15
|
+
"WorkflowReason",
|
|
14
16
|
]
|
|
15
17
|
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
|
|
16
20
|
|
|
17
21
|
class GPPError(Exception):
|
|
18
22
|
"""
|
|
@@ -38,6 +42,55 @@ class GPPValidationError(GPPClientError):
|
|
|
38
42
|
pass
|
|
39
43
|
|
|
40
44
|
|
|
45
|
+
@dataclass(frozen=True)
|
|
46
|
+
class WorkflowReason:
|
|
47
|
+
"""
|
|
48
|
+
One of GPP's reasons about an observation's workflow, word for word.
|
|
49
|
+
|
|
50
|
+
Attributes
|
|
51
|
+
----------
|
|
52
|
+
severity : str
|
|
53
|
+
``"ERROR"`` when it has to be fixed, ``"WARNING"`` when it only has to be
|
|
54
|
+
reviewed (GPP keeps the observation from ``READY`` until it is dismissed).
|
|
55
|
+
code : str
|
|
56
|
+
GPP's ``ObservationValidationCode``.
|
|
57
|
+
message : str
|
|
58
|
+
GPP's text.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
severity: str
|
|
62
|
+
code: str
|
|
63
|
+
message: str
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class GPPWorkflowTransitionError(GPPValidationError):
|
|
67
|
+
"""
|
|
68
|
+
Raised when GPP does not allow the requested workflow state.
|
|
69
|
+
|
|
70
|
+
Attributes
|
|
71
|
+
----------
|
|
72
|
+
requested : str
|
|
73
|
+
The state asked for.
|
|
74
|
+
allowed : list[str]
|
|
75
|
+
The states GPP allows from the current one.
|
|
76
|
+
reasons : list[WorkflowReason]
|
|
77
|
+
GPP's reasons, errors before warnings. Empty when GPP gives none.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def __init__(
|
|
81
|
+
self,
|
|
82
|
+
message: str,
|
|
83
|
+
*,
|
|
84
|
+
requested: str,
|
|
85
|
+
allowed: list[str],
|
|
86
|
+
reasons: list[WorkflowReason],
|
|
87
|
+
) -> None:
|
|
88
|
+
super().__init__(message)
|
|
89
|
+
self.requested = requested
|
|
90
|
+
self.allowed = allowed
|
|
91
|
+
self.reasons = reasons
|
|
92
|
+
|
|
93
|
+
|
|
41
94
|
class GPPRetryableError(GPPError):
|
|
42
95
|
"""
|
|
43
96
|
Raised for errors that may be transient and worth retrying.
|