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
490 stars 260 forks source link

Add context information when executing a process #1560

Closed francescoingv closed 7 months ago

francescoingv commented 7 months ago

It would be useful for a process manager to be given some context information regarding the current request, in addition to what is already specified in the OAProc standard, for example if the client sends some custom HTTP header.

Additionally, pygeoapi core may wish to also send some context information to be used during job execution, like some metadata or other config values.

With this in mind we could add an additional parameter to the process_manager's execute_process() method that would provide this context. Something like this:

def execute_process(
            self,
            process_id: str,
            data_dict: dict,
            execution_mode: Optional[RequestedProcessExecutionMode] = None,
+           context: dict
) -> Tuple[str, Any, JobStatus, Optional[Dict[str, str]]]:
    ...

As for the content of this new context dictionary, we can decide what would be valuable to include, but at least the request's HTTP headers already seem like a good option. Some other relevant things might be related to log information, and any other general configuration values.

This pattern of enhancing an execution with contextual information would be similar to what github actions does, for example (where it provides also a way to get context information about the current environment.

Describe alternatives you've considered The current implementation does not really allow a running job to be given more context than process-related inputs, so there does not seem to be much alternative other than changing the signature of the execute_process() method.

ricardogsilva commented 7 months ago

We discussed this topic at the Évora pygeoapi code sprint and decided that this could be implemented outside of pygeoapi core without much effort.

A possible way would be to have a middleware that puts the context information into the pygeoapi environment and then have custom processes get this from their env.

So I guess this issue can be closed.

francbartoli commented 7 months ago

@ricardogsilva I'm going to close this, can you please open a dedicated ticket in fastgeoapi