From 5769c701ea1c60453a72c7de3cf97d6a2aa71c3f Mon Sep 17 00:00:00 2001 From: FrancescoIngv Date: Wed, 1 Jul 2026 16:26:32 +0200 Subject: [PATCH 1/2] Solve issue #2382 BaseProcessor: added hook remove_resources() to enable derived classes to handle removal of resources PostgreSQLManager and TinyDBManager: modified delete_job() to call processor.remove_resources(job_id) when result files are removed. DummyManager and MongoDBManager: do not modified as not handling result files --- pygeoapi/process/base.py | 28 ++++++++++++++++++++++++++ pygeoapi/process/manager/postgresql.py | 5 +++++ pygeoapi/process/manager/tinydb_.py | 5 +++++ 3 files changed, 38 insertions(+) diff --git a/pygeoapi/process/base.py b/pygeoapi/process/base.py index a3dc05279..c6b435275 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: From 4e221d68a5083c108142866a1910f0eec02f6a58 Mon Sep 17 00:00:00 2001 From: FrancescoIngv Date: Wed, 1 Jul 2026 16:37:33 +0200 Subject: [PATCH 2/2] fixed whitespaces --- pygeoapi/process/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygeoapi/process/base.py b/pygeoapi/process/base.py index c6b435275..588377c7e 100644 --- a/pygeoapi/process/base.py +++ b/pygeoapi/process/base.py @@ -99,7 +99,7 @@ def remove_resources(self, job_id: str) -> None: 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().