1111from app .platforms .dispatcher import register_processing_platform
1212from app .schemas import (
1313 ProcessTypeEnum ,
14+ ProcessingStatusEnum ,
1415 ServiceDetails ,
1516)
1617
@@ -104,15 +105,6 @@ def _get_process_id(self, url: str) -> str:
104105 return process_id
105106
106107 def execute_job (self , title : str , details : ServiceDetails , parameters : dict ) -> str :
107- """
108- Execute a processing job on the platform with the given service ID and parameters.
109-
110- :param title: The title of the job to be executed.
111- :param details: The service details containing the service ID and application.
112- :param parameters: The parameters required for the job execution.
113- :return: Return the ID of the job that was created
114- """
115-
116108 try :
117109 process_id = self ._get_process_id (details .application )
118110
@@ -130,8 +122,47 @@ def execute_job(self, title: str, details: ServiceDetails, parameters: dict) ->
130122
131123 return job .job_id
132124 except Exception as e :
133- logger .exception (f"Failed to execute openEO job: { e } " )
134- raise SystemError ("Failed to execute openEO job" )
125+ logger .exception ("Failed to execute openEO job" )
126+ raise SystemError ("Failed to execute openEO job" ) from e
127+
128+ def _map_openeo_status (self , status : str ) -> ProcessingStatusEnum :
129+ """
130+ Map the status returned by openEO to a status known within the API.
131+
132+ :param status: Status text returned by openEO.
133+ :return: ProcessingStatusEnum corresponding to the input.
134+ """
135+
136+ logger .debug ("Mapping openEO status %r to ProcessingStatusEnum" , status )
137+
138+ mapping = {
139+ "created" : ProcessingStatusEnum .CREATED ,
140+ "queued" : ProcessingStatusEnum .QUEUED ,
141+ "running" : ProcessingStatusEnum .RUNNING ,
142+ "cancelled" : ProcessingStatusEnum .CANCELED ,
143+ "finished" : ProcessingStatusEnum .FINISHED ,
144+ "error" : ProcessingStatusEnum .FAILED ,
145+ }
146+
147+ try :
148+ return mapping [status .lower ()]
149+ except (AttributeError , KeyError ):
150+ logger .warning ("Mapping of unknown openEO status: %r" , status )
151+ return ProcessingStatusEnum .UNKNOWN
152+
153+ def get_job_status (
154+ self , job_id : str , details : ServiceDetails
155+ ) -> ProcessingStatusEnum :
156+ try :
157+ logger .debug (f"Fetching job status for openEO job with ID { job_id } " )
158+ connection = self ._setup_connection (details .service )
159+ job = connection .job (job_id )
160+ return self ._map_openeo_status (job .status ())
161+ except Exception as e :
162+ logger .exception (f"Failed to fetch status for openEO job with ID { job_id } " )
163+ raise SystemError (
164+ f"Failed to fetch status openEO job with ID { job_id } "
165+ ) from e
135166
136167
137168register_processing_platform (ProcessTypeEnum .OPENEO , OpenEOPlatform )
0 commit comments