diff --git a/pygeoapi/process/base.py b/pygeoapi/process/base.py index a3dc05279..588377c7e 100644 --- a/pygeoapi/process/base.py +++ b/pygeoapi/process/base.py @@ -89,6 +89,34 @@ def execute(self, data: dict, outputs: Optional[dict] = None raise NotImplementedError() + def remove_resources(self, job_id: str) -> None: + """ + Remove resorces (if any) created by the Processor for the specific + job_id. + E.g. resources created by the Processor for the job_id to be accessed + by reference. + Note: only the Processor is aware of the allocated resources and how to + handle (add/remove) them. + + :param job_id: the job_id associated to the resources to be removed. + + The function should be called by the Manager upon receiving a request + to delete_job(). + + The function should be implemented only by the Processors creating + job_id specific resources as result of a call to execute(), + where the resources are expected to become unavailable when the job + were deleted. + + For the implementing Processors, the Processor needs to have an + internal way to map job_id to the resources specific to that job_id. + + No exception is expected to be raised where the remove operation will + fail for any reason. + """ + + pass + def __repr__(self): return f' {self.name}' diff --git a/pygeoapi/process/manager/postgresql.py b/pygeoapi/process/manager/postgresql.py index 7a2adc559..cfd63eafb 100644 --- a/pygeoapi/process/manager/postgresql.py +++ b/pygeoapi/process/manager/postgresql.py @@ -254,6 +254,11 @@ def delete_job(self, job_id: str) -> bool: except FileNotFoundError: pass + # remove resources if present + process_id = job_result.get('process_id') + processor = self.get_processor(process_id) + processor.remove_resources(job_id) + return rowcount == 1 def get_job_result(self, job_id: str) -> Tuple[str, Any]: diff --git a/pygeoapi/process/manager/tinydb_.py b/pygeoapi/process/manager/tinydb_.py index c15e9d36a..0a638dd59 100644 --- a/pygeoapi/process/manager/tinydb_.py +++ b/pygeoapi/process/manager/tinydb_.py @@ -161,6 +161,11 @@ def delete_job(self, job_id: str) -> bool: with self._db() as db: removed = bool(db.remove(tinydb.where('identifier') == job_id)) + # remove resources if present + process_id = job_result.get('process_id') + processor = self.get_processor(process_id) + processor.remove_resources(job_id) + return removed def get_job(self, job_id: str) -> dict: