Skip to content

Commit

Permalink
rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kandharvishnuu authored and pierrejeambrun committed Nov 25, 2024
1 parent c8efa51 commit 66cf9e1
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 346 deletions.
69 changes: 0 additions & 69 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3951,75 +3951,6 @@ paths:
schema:
type: string
title: Task Id
- name: map_index
in: query
required: false
schema:
type: integer
default: -1
title: Map Index
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/TaskInstanceHistoryCollectionResponse'
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/{map_index}/tries:
get:
tags:
- Task Instance
summary: Get Mapped Task Instance Tries
operationId: get_mapped_task_instance_tries
parameters:
- name: dag_id
in: path
required: true
schema:
type: string
title: Dag Id
- name: dag_run_id
in: path
required: true
schema:
type: string
title: Dag Run Id
- name: task_id
in: path
required: true
schema:
type: string
title: Task Id
- name: map_index
in: path
required: true
schema:
type: integer
title: Map Index
responses:
'200':
description: Successful Response
Expand Down
35 changes: 6 additions & 29 deletions airflow/api_fastapi/core_api/routes/public/task_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from __future__ import annotations

from typing import Annotated, Literal
from typing import Annotated, Literal, cast

from fastapi import Depends, HTTPException, Request, status
from sqlalchemy.orm import Session, joinedload
Expand Down Expand Up @@ -245,9 +245,9 @@ def get_task_instance_tries(
dag_run_id: str,
task_id: str,
session: Annotated[Session, Depends(get_session)],
map_index: int = -1,
) -> TaskInstanceHistoryCollectionResponse:
"""Get list of task instances history."""
map_index = -1

def _query(orm_object: Base) -> Select:
query = select(orm_object).where(
Expand All @@ -262,43 +262,20 @@ def _query(orm_object: Base) -> Select:
tis = session.scalars(
_query(TI).where(or_(TI.state != TaskInstanceState.UP_FOR_RETRY, TI.state.is_(None)))
).all()
task_instance_select = session.scalars(_query(TIH)).all() + tis
task_instances = session.scalars(_query(TIH)).all() + tis

if not task_instance_select:
if not task_instances:
raise HTTPException(
status.HTTP_404_NOT_FOUND,
f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found",
)
task_instances = [
TaskInstanceHistoryResponse.model_validate(task_instance, from_attributes=True)
for task_instance in task_instance_select
]

return TaskInstanceHistoryCollectionResponse(
task_instances=task_instances,
task_instances=cast(list[TaskInstanceHistoryResponse], task_instances),
total_entries=len(task_instances),
)


@task_instances_router.get(
task_instances_prefix + "/{task_id}/{map_index}/tries",
responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
)
def get_mapped_task_instance_tries(
dag_id: str,
dag_run_id: str,
task_id: str,
session: Annotated[Session, Depends(get_session)],
map_index: int,
) -> TaskInstanceHistoryCollectionResponse:
return get_task_instance_tries(
dag_id=dag_id,
dag_run_id=dag_run_id,
task_id=task_id,
map_index=map_index,
session=session,
)


@task_instances_router.get(
task_instances_prefix + "/{task_id}/{map_index}",
responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
Expand Down
29 changes: 1 addition & 28 deletions airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,43 +1102,16 @@ export const UseTaskInstanceServiceGetTaskInstanceTriesKeyFn = (
{
dagId,
dagRunId,
mapIndex,
taskId,
}: {
dagId: string;
dagRunId: string;
mapIndex?: number;
taskId: string;
},
queryKey?: Array<unknown>,
) => [
useTaskInstanceServiceGetTaskInstanceTriesKey,
...(queryKey ?? [{ dagId, dagRunId, mapIndex, taskId }]),
];
export type TaskInstanceServiceGetMappedTaskInstanceTriesDefaultResponse =
Awaited<ReturnType<typeof TaskInstanceService.getMappedTaskInstanceTries>>;
export type TaskInstanceServiceGetMappedTaskInstanceTriesQueryResult<
TData = TaskInstanceServiceGetMappedTaskInstanceTriesDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const useTaskInstanceServiceGetMappedTaskInstanceTriesKey =
"TaskInstanceServiceGetMappedTaskInstanceTries";
export const UseTaskInstanceServiceGetMappedTaskInstanceTriesKeyFn = (
{
dagId,
dagRunId,
mapIndex,
taskId,
}: {
dagId: string;
dagRunId: string;
mapIndex: number;
taskId: string;
},
queryKey?: Array<unknown>,
) => [
useTaskInstanceServiceGetMappedTaskInstanceTriesKey,
...(queryKey ?? [{ dagId, dagRunId, mapIndex, taskId }]),
...(queryKey ?? [{ dagId, dagRunId, taskId }]),
];
export type TaskInstanceServiceGetMappedTaskInstanceDefaultResponse = Awaited<
ReturnType<typeof TaskInstanceService.getMappedTaskInstance>
Expand Down
50 changes: 1 addition & 49 deletions airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,6 @@ export const prefetchUseTaskInstanceServiceGetTaskInstanceDependencies1 = (
* @param data.dagId
* @param data.dagRunId
* @param data.taskId
* @param data.mapIndex
* @returns TaskInstanceHistoryCollectionResponse Successful Response
* @throws ApiError
*/
Expand All @@ -1463,68 +1462,21 @@ export const prefetchUseTaskInstanceServiceGetTaskInstanceTries = (
{
dagId,
dagRunId,
mapIndex,
taskId,
}: {
dagId: string;
dagRunId: string;
mapIndex?: number;
taskId: string;
},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseTaskInstanceServiceGetTaskInstanceTriesKeyFn({
dagId,
dagRunId,
mapIndex,
taskId,
}),
queryFn: () =>
TaskInstanceService.getTaskInstanceTries({
dagId,
dagRunId,
mapIndex,
taskId,
}),
});
/**
* Get Mapped Task Instance Tries
* @param data The data for the request.
* @param data.dagId
* @param data.dagRunId
* @param data.taskId
* @param data.mapIndex
* @returns TaskInstanceHistoryCollectionResponse Successful Response
* @throws ApiError
*/
export const prefetchUseTaskInstanceServiceGetMappedTaskInstanceTries = (
queryClient: QueryClient,
{
dagId,
dagRunId,
mapIndex,
taskId,
}: {
dagId: string;
dagRunId: string;
mapIndex: number;
taskId: string;
},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseTaskInstanceServiceGetMappedTaskInstanceTriesKeyFn({
dagId,
dagRunId,
mapIndex,
taskId,
}),
queryFn: () =>
TaskInstanceService.getMappedTaskInstanceTries({
dagId,
dagRunId,
mapIndex,
taskId,
}),
TaskInstanceService.getTaskInstanceTries({ dagId, dagRunId, taskId }),
});
/**
* Get Mapped Task Instance
Expand Down
49 changes: 1 addition & 48 deletions airflow/ui/openapi-gen/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,6 @@ export const useTaskInstanceServiceGetTaskInstanceDependencies1 = <
* @param data.dagId
* @param data.dagRunId
* @param data.taskId
* @param data.mapIndex
* @returns TaskInstanceHistoryCollectionResponse Successful Response
* @throws ApiError
*/
Expand All @@ -1769,70 +1768,24 @@ export const useTaskInstanceServiceGetTaskInstanceTries = <
{
dagId,
dagRunId,
mapIndex,
taskId,
}: {
dagId: string;
dagRunId: string;
mapIndex?: number;
taskId: string;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useQuery<TData, TError>({
queryKey: Common.UseTaskInstanceServiceGetTaskInstanceTriesKeyFn(
{ dagId, dagRunId, mapIndex, taskId },
{ dagId, dagRunId, taskId },
queryKey,
),
queryFn: () =>
TaskInstanceService.getTaskInstanceTries({
dagId,
dagRunId,
mapIndex,
taskId,
}) as TData,
...options,
});
/**
* Get Mapped Task Instance Tries
* @param data The data for the request.
* @param data.dagId
* @param data.dagRunId
* @param data.taskId
* @param data.mapIndex
* @returns TaskInstanceHistoryCollectionResponse Successful Response
* @throws ApiError
*/
export const useTaskInstanceServiceGetMappedTaskInstanceTries = <
TData = Common.TaskInstanceServiceGetMappedTaskInstanceTriesDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[],
>(
{
dagId,
dagRunId,
mapIndex,
taskId,
}: {
dagId: string;
dagRunId: string;
mapIndex: number;
taskId: string;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useQuery<TData, TError>({
queryKey: Common.UseTaskInstanceServiceGetMappedTaskInstanceTriesKeyFn(
{ dagId, dagRunId, mapIndex, taskId },
queryKey,
),
queryFn: () =>
TaskInstanceService.getMappedTaskInstanceTries({
dagId,
dagRunId,
mapIndex,
taskId,
}) as TData,
...options,
Expand Down
Loading

0 comments on commit 66cf9e1

Please sign in to comment.