Skip to content

Commit

Permalink
Add function to check if pipeline is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Oct 25, 2023
1 parent 39e89e5 commit d2db155
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/isar_exr/api/energy_robotics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def get_mission_status(self, exr_robot_id: str) -> MissionStatus:
response_dict: dict[str, Any] = self.client.query(
dsl_gql(current_mission_execution_query), params
)

if response_dict["currentMissionExecution"] is None:
raise NoMissionRunningException

step_status = ExrMissionStatus(
response_dict["currentMissionExecution"]["status"]
)
Expand Down Expand Up @@ -661,6 +665,43 @@ def commit_site_to_snapshot(self, stage_id: str) -> str:

return response_dict["commitSiteChanges"]["id"]

def is_pipeline_completed(self, site_id: str) -> bool:
variable_definitions_graphql: DSLVariableDefinitions = DSLVariableDefinitions()

current_processing_pipeline: DSLQuery = DSLQuery(
self.schema.Query.currentSiteSnapshotHeadSelectionProcessingPipeline.args(
siteId=variable_definitions_graphql.siteId
).select(
self.schema.ProcessingPipelineType.stages.select(
self.schema.ProcessingPipelineStageType.state
)
)
)

current_processing_pipeline.variable_definitions = variable_definitions_graphql

params: dict = {"siteId": site_id}

try:
response_dict: dict[str, Any] = self.client.query(
dsl_gql(current_processing_pipeline), params
)
except Exception as e:
message: str = "Could not get current processing pipeline"
self.logger.error(message)
raise RobotAPIException(
error_description=message,
)

if (
response_dict["currentSiteSnapshotHeadSelectionProcessingPipeline"][
"stages"
][0]["state"]
== "COMPLETED"
):
return True
return False

def set_snapshot_as_head(self, snapshot_id: str, site_id: str) -> str:
params: dict[str, Any] = {"siteId": site_id, "siteSnapshotId": snapshot_id}

Expand Down
3 changes: 3 additions & 0 deletions src/isar_exr/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self) -> None:
"../../../docs/schema.graphql"
)

# API sleep time
API_SLEEP_TIME: int = Field(default=1)

model_config = SettingsConfigDict(
env_prefix="EXR_",
env_file_encoding="utf-8",
Expand Down
4 changes: 4 additions & 0 deletions src/isar_exr/robotinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ def initiate_mission(self, mission: Mission) -> None:
poi_ids.append(poi_id)

snapshot_id: str = self.api.commit_site_to_snapshot(stage_id=stage_id)

self.api.set_snapshot_as_head(
snapshot_id=snapshot_id, site_id=settings.ROBOT_EXR_SITE_ID
)

while not self.api.is_pipeline_completed(site_id=settings.ROBOT_EXR_SITE_ID):
time.sleep(settings.API_SLEEP_TIME)

mission_definition_id: str = self.api.create_mission_definition(
site_id=settings.ROBOT_EXR_SITE_ID,
mission_name=mission.id,
Expand Down

0 comments on commit d2db155

Please sign in to comment.