Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pygeoapi/process/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<BaseProcessor> {self.name}'

Expand Down
5 changes: 5 additions & 0 deletions pygeoapi/process/manager/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
5 changes: 5 additions & 0 deletions pygeoapi/process/manager/tinydb_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading