Skip to content

Commit 8488eed

Browse files
authored
Merge pull request #210 from DalgoT4D/get-scheduled-flow-runs
get scheduled flow-runs for a deployment
2 parents 9706d58 + d66cd69 commit 8488eed

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

proxy/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
get_flow_runs_by_name,
2929
set_deployment_schedule,
3030
get_deployment,
31+
get_deployment_scheduled_flow_runs,
3132
get_flow_run,
3233
retry_flow_run,
3334
create_secret_block,
@@ -489,6 +490,21 @@ def put_dataflow_v1(deployment_id, payload: DeploymentUpdate2):
489490
return {"success": 1}
490491

491492

493+
@app.get("/proxy/v1/deployments/get_scheduled_flow_runs")
494+
def get_dataflow_scheduled_flow_runs(deployment_id: str):
495+
"""fetch scheduled flow-runs for a deployment"""
496+
if not isinstance(deployment_id, str):
497+
raise TypeError("deployment_id must be a string")
498+
try:
499+
res = get_deployment_scheduled_flow_runs(deployment_id)
500+
except Exception as error:
501+
logger.exception(error)
502+
raise HTTPException(
503+
status_code=400, detail="failed to fetch scheduled flow-runs for deployment"
504+
) from error
505+
return {"flow_runs": res}
506+
507+
492508
@app.post("/proxy/flow_run/")
493509
async def get_flowrun(payload: FlowRunRequest):
494510
"""look up a flow run by name and return id if found"""

proxy/service.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,19 @@ def get_deployment(deployment_id: str) -> dict:
725725
return res
726726

727727

728+
def get_deployment_scheduled_flow_runs(deployment_id: str) -> dict:
729+
"""fetch scheduled flow-runs for a deployment"""
730+
if not isinstance(deployment_id, str):
731+
raise TypeError("deployment_id must be a string")
732+
res = prefect_post(
733+
"deployments/get_scheduled_flow_runs",
734+
{
735+
"deployment_ids": [deployment_id],
736+
},
737+
)
738+
return res
739+
740+
728741
def update_flow_run_final_state(flow_run: dict) -> dict:
729742
"""
730743
fetch tasks of the flow_run & checks for the custom flow_run state

tests/test_main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
post_run_dbtcore_flow_v1,
3636
post_dataflow_v1,
3737
put_dataflow_v1,
38+
get_dataflow_scheduled_flow_runs,
3839
get_long_running_flows,
3940
patch_dbt_cloud_creds,
4041
get_dbt_cloud_creds,
@@ -588,6 +589,15 @@ def test_put_dataflow_v1_success():
588589
assert result == {"success": 1}
589590

590591

592+
def test_get_dataflow_scheduled_flow_runs():
593+
with patch(
594+
"proxy.main.get_deployment_scheduled_flow_runs"
595+
) as mock_get_deployment_scheduled_flow_runs:
596+
mock_get_deployment_scheduled_flow_runs.return_value = [{"id": "flow_run_id"}]
597+
result = get_dataflow_scheduled_flow_runs("deployment-id")
598+
assert result == {"flow_runs": [{"id": "flow_run_id"}]}
599+
600+
591601
def test_get_flow_run_by_id_badparams():
592602
with pytest.raises(TypeError) as excinfo:
593603
get_flow_run_by_id(123)

tests/test_service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
post_deployment_v1,
5353
put_deployment_v1,
5454
get_deployment,
55+
get_deployment_scheduled_flow_runs,
5556
CronSchedule,
5657
post_deployment_flow_run,
5758
create_secret_block,
@@ -1091,6 +1092,19 @@ def test_get_deployment(mock_get: Mock):
10911092
assert response == "retval"
10921093

10931094

1095+
@patch("proxy.service.prefect_post")
1096+
def test_get_deployment_scheduled_flow_runs(mock_post: Mock):
1097+
mock_post.return_value = [{"id": "flow_run_id"}]
1098+
response = get_deployment_scheduled_flow_runs("deployment-id")
1099+
mock_post.assert_called_once_with(
1100+
"deployments/get_scheduled_flow_runs",
1101+
{
1102+
"deployment_ids": ["deployment-id"],
1103+
},
1104+
)
1105+
assert response == [{"id": "flow_run_id"}]
1106+
1107+
10941108
def test_get_flow_runs_by_deployment_id_type_error():
10951109
with pytest.raises(TypeError):
10961110
get_flow_runs_by_deployment_id(123, 10, "")

0 commit comments

Comments
 (0)