geopython / pygeoapi

pygeoapi is a Python server implementation of the OGC API suite of standards. The project emerged as part of the next generation OGC API efforts in 2018 and provides the capability for organizations to deploy a RESTful OGC API endpoint using OpenAPI, GeoJSON, and HTML. pygeoapi is open source and released under an MIT license.
https://pygeoapi.io
MIT License
459 stars 250 forks source link

Process: allow the processor to know the process_id #1676

Closed francescoingv closed 2 weeks ago

francescoingv commented 3 weeks ago

Is your feature request related to a problem? Please describe. There are use cases where the process may benefit from knowing the processed job_id. E.g.: a specific ProcessManager may want to read the output files from the process: the process would then write job specific files in the job_id directory.

Describe the solution you'd like The setting should happen before the call to process.execute().

One solution would be the BaseManager try to set the processor.job_id, but do nothing if it fails.

BaseManager.execute_process()
        processor = self.get_processor(process_id)
+        try:
+           # if the processor can set the job id, do it.
+            processor.set_job_id(job_id)
+        except AttributeError:
+            pass

Even better: the BaseProcessor defines a method set_job_id() that does nothing. The method is available for derived classes, where needed.

BaseManager.execute_process()
        processor = self.get_processor(process_id)
+          processor.set_job_id(job_id)

BaseProcessor
+    def set_job_id(self, job_id: str) -> None:
+        """
+        set the job_id within the processor
+        To be implemented by derived classes where required.
+        """
+        pass

Describe alternatives you've considered A derived BaseManager class implementing the solution should modify the BaseManager.execute_process(). Given the minimal change, also not affecting any in place code, I would prefer to have the solution included in the release.

Additional context If approved I would like to submit a PR with the second solution.

tomkralidis commented 3 weeks ago

2024-06-13: +1 for option 2 implementation @francescoingv.