Skip to content

Commit 904325a

Browse files
committed
[DOP-29112] rename filters
1 parent e12de3a commit 904325a

File tree

10 files changed

+36
-30
lines changed

10 files changed

+36
-30
lines changed

data_rentgen/db/repositories/run.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ async def paginate(
9494
job_id: int | None,
9595
parent_run_id: UUID | None,
9696
search_query: str | None,
97-
job_types: Collection[str],
98-
statuses: Collection[str],
97+
job_type: Collection[str],
98+
status: Collection[str],
9999
) -> PaginationDTO[Run]:
100100
# do not use `tuple_(Run.created_at, Run.id).in_(...),
101101
# as this is too complex filter for Postgres to make an optimal query plan
@@ -132,9 +132,9 @@ async def paginate(
132132
where.append(Run.job_id == job_id)
133133
if parent_run_id:
134134
where.append(Run.parent_run_id == parent_run_id)
135-
if statuses:
136-
serialize_statuses: Collection[RunStatus] = [RunStatus[status] for status in statuses]
137-
where.append(Run.status == any_(serialize_statuses)) # type: ignore[arg-type]
135+
if status:
136+
serialize_status: Collection[RunStatus] = [RunStatus[status] for status in status]
137+
where.append(Run.status == any_(serialize_status)) # type: ignore[arg-type]
138138

139139
query: Select | CompoundSelect
140140
order_by: list[ColumnElement | SQLColumnExpression]
@@ -165,8 +165,8 @@ async def paginate(
165165
query = select(Run).where(*where)
166166
order_by = [Run.created_at.desc(), Run.id.desc()]
167167

168-
if job_types:
169-
query = query.join(Job, Run.job_id == Job.id).where(Job.type == any_(job_types)) # type: ignore[arg-type]
168+
if job_type:
169+
query = query.join(Job, Run.job_id == Job.id).where(Job.type == any_(job_type)) # type: ignore[arg-type]
170170

171171
options = [selectinload(Run.started_by_user)]
172172
return await self._paginate_by_query(

data_rentgen/server/api/v1/router/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ async def runs(
3939
job_id=query_args.job_id,
4040
parent_run_id=query_args.parent_run_id,
4141
search_query=query_args.search_query,
42-
job_types=query_args.job_types,
43-
statuses=query_args.statuses,
42+
job_type=query_args.job_type,
43+
status=query_args.status,
4444
)
4545
return PageResponseV1[RunDetailedResponseV1].from_pagination(pagination)
4646

data_rentgen/server/schemas/v1/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ class RunsQueryV1(PaginateQueryV1):
147147
examples=["01913217-b761-7b1a-bb52-489da9c8b9c8"],
148148
)
149149

150-
job_types: list[str] = Field(
150+
job_type: list[str] = Field(
151151
default_factory=list,
152152
description="Filter runs by type of a Job",
153153
examples=["SPARK_APPLICATION", "AIRFLOW_TASK"],
154154
)
155-
statuses: list[RunStatusForQueryV1] = Field(default_factory=list, description="Filter runs by status")
155+
status: list[RunStatusForQueryV1] = Field(default_factory=list, description="Filter runs by status")
156156

157157
search_query: str | None = Field(
158158
default=None,

data_rentgen/server/services/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ async def paginate(
8080
job_id: int | None,
8181
parent_run_id: UUID | None,
8282
search_query: str | None,
83-
job_types: Collection[str],
84-
statuses: Collection[str],
83+
job_type: Collection[str],
84+
status: Collection[str],
8585
) -> RunServicePaginatedResult:
8686
pagination = await self._uow.run.paginate(
8787
page=page,
@@ -92,8 +92,8 @@ async def paginate(
9292
job_id=job_id,
9393
parent_run_id=parent_run_id,
9494
search_query=search_query,
95-
job_types=job_types,
96-
statuses=statuses,
95+
job_type=job_type,
96+
status=status,
9797
)
9898
run_ids = [item.id for item in pagination.items]
9999
input_stats = await self._uow.input.get_stats_by_run_ids(run_ids)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Add new query parameters for ``/api/v1/runs`` endpoint:
2+
3+
- job_type: ``list[str]`` - filter by corresponding job type. For example ``SPARK_APLICATION``. You can use ``/api/v1/jobs/types`` to get all job types.
4+
- status:``list[RunStatus]`` - filter by runs statuses.

tests/test_server/fixtures/factories/run.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,13 @@ async def runs_search(
195195
{"name": "airflow_dag_name", "type": "AIRFLOW_DAG"},
196196
]
197197
runs_kwargs = [
198-
{"external_id": "application_1638922609021_0001", "status": 3},
199-
{"external_id": "application_1638922609021_0002", "status": 1},
200-
{"external_id": "extract_task_0001", "status": 0},
201-
{"external_id": "extract_task_0002", "status": 2},
198+
{"external_id": "application_1638922609021_0001", "status": RunStatus.KILLED},
199+
{
200+
"external_id": "application_1638922609021_0002",
201+
"status": RunStatus.SUCCEEDED,
202+
},
203+
{"external_id": "extract_task_0001", "status": RunStatus.STARTED},
204+
{"external_id": "extract_task_0002", "status": RunStatus.FAILED},
202205
]
203206
started_at = datetime.now(tz=UTC)
204207
async with async_session_maker() as async_session:

tests/test_server/test_runs/test_get_runs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ async def test_get_runs_missing_fields(
3636
"message": "Value error, input should contain either 'since', 'run_id', 'job_id', 'parent_run_id' or 'search_query' field",
3737
"context": {},
3838
"input": {
39-
"statuses": [],
40-
"job_types": [],
39+
"status": [],
40+
"job_type": [],
4141
"page": 1,
4242
"page_size": 20,
4343
"run_id": [],

tests/test_server/test_runs/test_get_runs_by_job_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ async def test_get_runs_by_job_id_missing_since(
3838
"message": "Value error, 'job_id' can be passed only with 'since'",
3939
"context": {},
4040
"input": {
41-
"statuses": [],
42-
"job_types": [],
41+
"status": [],
42+
"job_type": [],
4343
"page": 1,
4444
"page_size": 20,
4545
"job_id": str(new_run.job_id),

tests/test_server/test_runs/test_get_runs_by_parent_run_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ async def test_get_runs_by_job_id_missing_since(
3838
"message": "Value error, 'parent_run_id' can be passed only with 'since'",
3939
"context": {},
4040
"input": {
41-
"statuses": [],
42-
"job_types": [],
41+
"status": [],
42+
"job_type": [],
4343
"page": 1,
4444
"page_size": 20,
4545
"parent_run_id": str(new_run.parent_run_id),

tests/test_server/test_runs/test_search_runs.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ async def test_search_runs_missing_since(
3737
"message": "Value error, 'search_query' can be passed only with 'since'",
3838
"context": {},
3939
"input": {
40-
"statuses": [],
41-
"job_types": [],
40+
"status": [],
41+
"job_type": [],
4242
"page": 1,
4343
"page_size": 20,
4444
"run_id": [],
@@ -200,7 +200,7 @@ async def test_search_runs_by_job_type(
200200
headers={"Authorization": f"Bearer {mocked_user.access_token}"},
201201
params={
202202
"since": since.isoformat(),
203-
"job_types": ["SPARK_APPLICATION"],
203+
"job_type": ["SPARK_APPLICATION"],
204204
},
205205
)
206206

@@ -251,7 +251,6 @@ async def test_search_runs_by_status(
251251
) -> None:
252252
runs = await enrich_runs(
253253
[
254-
# runs sorted by id in descending order
255254
runs_search["extract_task_0001"],
256255
runs_search["application_1638922609021_0002"],
257256
],
@@ -264,7 +263,7 @@ async def test_search_runs_by_status(
264263
headers={"Authorization": f"Bearer {mocked_user.access_token}"},
265264
params={
266265
"since": since.isoformat(),
267-
"statuses": ["SUCCEEDED", "STARTED"],
266+
"status": ["SUCCEEDED", "STARTED"],
268267
},
269268
)
270269

0 commit comments

Comments
 (0)