diff --git a/app/README.md b/app/README.md index a88a3ba..1821838 100644 --- a/app/README.md +++ b/app/README.md @@ -16,7 +16,8 @@ To run the server, please execute the following from the root directory: ```bash pip3 install -r requirements.txt -PYTHONPATH=src uvicorn openapi_server.main:app --host 0.0.0.0 --port 8080 +cd unity-sps-ogc-processes-api/app +PYTHONPATH=src uvicorn unity_sps_ogc_processes_api.main:app --host 0.0.0.0 --port 8008 ``` and open your browser at `http://localhost:8080/docs/` to see the docs. diff --git a/app/src/openapi_server/impl/dru_api.py b/app/src/openapi_server/impl/dru_api.py index 1a2a034..0e397b2 100644 --- a/app/src/openapi_server/impl/dru_api.py +++ b/app/src/openapi_server/impl/dru_api.py @@ -170,22 +170,29 @@ def replace(self, processId: str, ogcapppkg: Ogcapppkg) -> None: detail=f"DAG file for process {processId} not found in the catalog", ) - # Optionally, you might want to refresh the DAG in Airflow + # Update the DAG in Airflow ems_api_auth = HTTPBasicAuth( self.settings.EMS_API_AUTH_USERNAME, self.settings.EMS_API_AUTH_PASSWORD.get_secret_value(), ) - response = requests.post( - f"{self.settings.EMS_API_URL}/dags/{processId}/dagRuns", + + # Determine if DAG is paused and retain state + response = requests.get( + f"{self.settings.EMS_API_URL}/dags/{ogcapppkg.process_description.id}", + auth=ems_api_auth, + ) + data = response.json() + is_paused = data.get("is_paused", False) + + # Request to replace the DAG in Airflow + response = requests.patch( + f"{self.settings.EMS_API_URL}/dags/{processId}", auth=ems_api_auth, - json={"is_paused": False}, # Unpause the DAG if it was paused + json={"is_paused": is_paused}, # Unpause the DAG if it was paused ) response.raise_for_status() - return Response( - status_code=status.HTTP_204_NO_CONTENT, - content=f"Process {processId} replaced successfully", - ) + return Response(status_code=status.HTTP_204_NO_CONTENT) except LockError: raise HTTPException( status_code=status.HTTP_503_SERVICE_UNAVAILABLE,