Hi, I'm using prefect1.0 on Cloud and I'm trying t...
# prefect-community
w
Hi, I'm using prefect1.0 on Cloud and I'm trying to save the flow's information like ID, excuetion time, version, e.t.c to my own database. Is there an API already provided by prefect to do that? If not, isn't there a good way to save the corresponding contents using the functions that have already been created? Give me a hand... 🙌
👀 1
✅ 1
I'm not sure if this is correct, but I found these pages at Prefect Docs about qusetion. https://docs-v1.prefect.io/core/advanced_tutorials/using-results.html https://docs-v1.prefect.io/core/concepts/configuration.html#configuration-precedence https://docs-v1.prefect.io/core/advanced_tutorials/custom-logs https://docs-v1.prefect.io/core/idioms/logging.html Which page is best for my situation? I checked that there is a way to connect to a custom postgreSQL when using prefect in the local environment, but since I want to use various functions of the cloud so i can't giveup the prefect cloud. Could you tell me in detail if there is a way?
b
Hello Wonsun, thanks for reaching out! I think the Interactive API may be useful to you to pull this information: https://docs-v1.prefect.io/orchestration/ui/interactive-api.html
w
Appreciate it Bianca! Technically, i want to get the information in python code, not in UI. Anyway, the page you pointed out gave me a clue, so I found a way to send a query to graphql with a python client. (this page) But there's a problem. I tried to write the same query and result in python as the query written in the UI(attatched image), but I got the following syntax error like second, third images from jupyter notebook. I'm not sure how to write the 'flow_runs' correctly in python. @Bianca Hoch
b
Here's something you can try, it works for me:
Copy code
import prefect
client = prefect.Client()

flows = client.graphql(
    {
        'query': {
            'flow': {
                'id'
            }
        }
    }
)

flow_run_list = []
for flow in flows['data']['flow']:
    flow_runs = client.graphql(
        {
        'query': {
            'flow (where: {id: {_eq: "'+flow['id']+'"}})':{
                'name,' #leave comma inside of quotes to get flow name
                'id,' #leave comma inside of quotes to get flow id
                'project_id,' #leave comma inside of quotes to get project_id
                'version,' #leave comma inside of quotes to get flow version
                'flow_runs':{
                    'id',
                    'name',
                    'state',
                    'start_time',
                    'end_time'
                }
            }
        }
        }   
    )
    flow_run_list.append(flow_runs)


print(flows)
print(flow_run_list)
w
Appreciate it Bianca 🙂
panda dancing 1