Hey! I have a non-python micro service that uses t...
# ask-community
d
Hey! I have a non-python micro service that uses the Prefect API to trigger a deployment. Is there a way to get the result of a flow run other than to use the Prefect Python client and call
.result()
on the created flow? My solution currently is creating a Python web server which this micro service would talk to, and that server would use the Prefect Python client on its behalf but that’s really awkward :( @Marvin
m
It seems I got a bit ahead of myself without specifying the precise queries. Let's try that again! To find a solution for retrieving a flow run result without the Python client, I'll look for information on using the Prefect API to access flow run results. Please give me a moment. I found some information for you regarding accessing flow run results without using the Python client. Here's what I gathered: In Prefect, one way to access flow run results without the Python client is by leveraging the Prefect API directly. This means you can interact with the run results through API calls instead. 1. Prefect API Access: Prefect's API allows you to manage run metadata and retrieve information about flow runs. You can perform actions like retrieving the last N completed flow runs using
read_flow_runs
. For example, using the API via
prefect.client.schemas
in Prefect 3.x, you can still get information about finished flow runs. The detailed usage of this feature can be seen in the Prefect API documentation. Check out this link for more details on how to interact with Prefect's API. 2. Custom Web Service: Continuing with the idea you mentioned, you can consider creating a custom RESTful service that interacts with the Prefect API under the hood. This service can expose endpoints that your microservice can call to retrieve flow results. It could act as a middle layer, translating your microservice requests into Prefect API calls. Summarizing, rather than going to the Python client alone, using the Prefect API directly can simplify your workflow and remove awkward dependencies. And just remember, developers occasionally endure our robot-related fate: making yet another API endpoint. Now, go forth and code with slightly less existential dread.
d
@Marvin Option 1 would not work as the run result is not available through the API as it’s stored in a persistent storage and the API only returns a file path.
m
It appears you're right about the limitations with the Prefect API when it comes to accessing the actual result content directly due to its storage mechanism. Here’s what I discovered about handling this scenario: 1. Result Persistence and Configuration: In Prefect, flow or task results that need to be persisted aren't directly available through the API unless configured to be stored in specific storage. Prefect supports result persistence as a feature, which can be globally enabled or customized for specific tasks. You can specify the storage mechanism using configurations like
PREFECT_DEFAULT_RESULT_STORAGE_BLOCK
or other settings related to result persistence. You can see more details on configuring result persistence using this guide: Prefect Results Documentation. 2. Custom Retrieval Method: If the API only provides a file path, the solution would involve ensuring that the file path points to an accessible storage from which your non-Python microservice can retrieve data. This could involve using cloud storage solutions such as AWS S3, Google Cloud Storage, or Azure Blob Storage. Your microservice can thus directly access the results from the storage service using its own SDK or API. 3. Alternative Setup: As a workaround, you might want to automate the process of accessing the result file path using Prefect's capabilities to log this information or ship it to a specific location that's accessible to your microservice. I understand these aren't perfect solutions, but with configurations, you can bridge the gap between the API and your service's needs. Unfortunately, in Prefect's current versions, this might be somewhat cumbersome, but definitely achievable with robust configuration. Now that we've delved into the labyrinth of Prefect's ways: remember, persistence is key, even in the face of obtuse file paths!
a
Hey @Daniel Adari what would that look like? Kick off a flow, get an endpoint you can poll from another service until the result is ready?
d
Hey @Alexander Azzam! Yup, I’m building a front end which abstracts many of the prefect internals so users can just run flows and get the flow’s result. Currently the UI will poll the status of the flow run until a completed state is detected and then I’ll query the result. I’m using an S3 bucket as the result storage block for all of my flows so I’m exposing my S3 as a static website and querying that, my results are pretty small so it works well. Would love a prefect feature that allows to do that dynamically for every flow and every storage block.
@Alexander Azzam Any insight here?
a
holy ghosting batman
sorry for showing up then disappearing lol
yeah so what you have set up is what I was going to pitch was basically using prefect's client to manage all of this stuff
tell me more about what you mean by
dynamically for every flow and every storage block
d
@Alexander Azzam No worries! You guys are busy building an awesome product :) I would love to be able to just query the Prefect API and get the actual result from that storage block. Also, I have tried using the prefect client, but have encountered a bug (can open an issue on GH) where if I run the client in a Prefect flow and configure that client to another Prefect instance, when retrieving the result using
fetch=True
it tries to load the block from the wrong instance, which is the one running the flow and not the configured one so it doesn’t find that block ID.