Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prefect query functions #177

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions utils/prefect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from prefect.client.schemas.filters import (
FlowRunFilter,
FlowRunFilterName,
FlowRunFilterParentFlowRunId,
FlowRunFilterTags,
)

Expand Down Expand Up @@ -58,26 +59,45 @@ def get_flow_run_name(flow_run_id):
return asyncio.run(_get_name(flow_run_id))


async def _flow_run_query(tags, flow_run_name=None):
flow_runs_by_name = []
async def _flow_run_query(
tags=None, flow_run_name=None, parent_flow_run_id=None, sort="START_TIME_DESC"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we will ever use the function in this way, but what happens if all parameters are None, do we filter nothing and retrieve all flows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It retrieves all flows, I just did a quick test at my end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good to know!

):
flow_run_filter_parent_flow_run_id = (
FlowRunFilterParentFlowRunId(any_=[parent_flow_run_id])
if parent_flow_run_id
else None
)
async with get_client() as client:
flow_runs = await client.read_flow_runs(
flow_run_filter=FlowRunFilter(
name=FlowRunFilterName(like_=flow_run_name),
parent_flow_run_id=flow_run_filter_parent_flow_run_id,
tags=FlowRunFilterTags(all_=tags),
),
sort="START_TIME_DESC",
sort=sort,
)
for flow_run in flow_runs:
if flow_run.state_name == "Failed":
flow_name = f"❌ {flow_run.name}"
elif flow_run.state_name == "Completed":
flow_name = f"✅ {flow_run.name}"
else:
flow_name = f"🕑 {flow_run.name}"
flow_runs_by_name.append({"label": flow_name, "value": str(flow_run.id)})
return flow_runs_by_name
return flow_runs


def query_flow_run(tags, flow_run_name=None):
return asyncio.run(_flow_run_query(tags, flow_run_name))
def get_flow_runs_by_name(flow_run_name=None, tags=None):
flow_runs_by_name = []
flow_runs = asyncio.run(_flow_run_query(tags, flow_run_name=flow_run_name))
for flow_run in flow_runs:
Wiebke marked this conversation as resolved.
Show resolved Hide resolved
if flow_run.state_name == "Failed":
flow_name = f"❌ {flow_run.name}"
elif flow_run.state_name == "Completed":
flow_name = f"✅ {flow_run.name}"
else:
flow_name = f"🕑 {flow_run.name}"
flow_runs_by_name.append({"label": flow_name, "value": str(flow_run.id)})
return flow_runs_by_name


def get_children_flow_run_ids(parent_flow_run_id, sort="START_TIME_ASC"):
children_flow_runs = asyncio.run(
_flow_run_query(parent_flow_run_id=parent_flow_run_id, sort=sort)
)
children_flow_run_ids = [
str(children_flow_run.id) for children_flow_run in children_flow_runs
]
return children_flow_run_ids
Loading