@@ -151,15 +151,64 @@ either sync or async, as both types are supported by the Prefect manager.
151151If you prefer, you can write Prefect flows, deploy them using any of the multiple techniques supported by Prefect
152152and then adapt them to run as pygeoapi processors.
153153
154- In order to do so, your Prefect flows need to implement the
155- [protocol](https://typing.python.org/en/latest/spec/protocol.html)
156- defined in `pygeoapi_prefect.PygeoapiPrefectFlowProtocol`
154+ In order to be runnable via pygeoapi, your flows need to :
155+
156+ 1. Implement the [protocol](https://typing.python.org/en/latest/spec/protocol.html)
157+ defined in `pygeoapi_prefect.PygeoapiPrefectFlowProtocol` :
158+
159+ ` ` ` python
160+ from typing import Protocol
161+
162+ class PygeoapiPrefectFlowProtocol(Protocol):
163+ def __call__(
164+ self,
165+ processor_id: str,
166+ pygeoapi_job_id: str,
167+ inputs: dict,
168+ outputs: dict | None = None,
169+ ) -> None: ...
170+ ` ` `
171+
172+ 2. The flow must have at least one Prefect task, which is where the processing output is be generated. This task
173+ must return the generated output, which enables it to be managed by
174+ [Prefect's result management facilities](https://docs.prefect.io/v3/advanced/results). This means this
175+ result-generating task must :
176+
177+ - Be configured to persist results;
178+ - Be configured with a result storage key that uses the pygeoapi job id - this is needed in order to ensure
179+ pygeoapi is able to reconstruct the result's storage key for retrieval;
180+ - The generated output must be a two-element tuple where the first element is the media type and the second
181+ element is the actual output.
182+
183+ 3. The flow must already have been deployed in your Prefect environment. You can use any of the Prefect deployment
184+ types (local processes, docker containers, k8s, etc.). Check the [examples](docker-example.md) section for more information
185+
186+ 4. Your pygeoapi configuration for the process needs to include a `prefect` section, with `deployment` and `metadata`
187+ sub-sections.
188+
189+ This means that a very minimal flow looks like this :
157190
158191` ` ` python
159- from prefect import flow
192+ from prefect import flow, task
160193
161194@flow()
162- def my_custom_flow()
195+ def my_custom_flow(
196+ processor_id: str,
197+ pygeoapi_job_id: str,
198+ inputs: dict,
199+ outputs: dict | None = None
200+ ) -> None:
201+ # perform whatever preparatory steps
202+ generate_result(pygeoapi_job_id)
203+
204+
205+ @task(
206+ persist_result=True,
207+ result_storage_key="{parameters[pygeoapi_job_id].pickle}",
208+ log_prints=True
209+ )
210+ def generate_result(pygeoapi_job_id: str) -> tuple[str, bytes]:
211+ return "text/plain", "Hi there, I am a result".encode()
163212
164213` ` `
165214
0 commit comments