Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,78 @@ paths:
schema:
type: string
title: Run Id
- name: start_date_gte
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Start Date Gte
- name: start_date_gt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Start Date Gt
- name: start_date_lte
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Start Date Lte
- name: start_date_lt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Start Date Lt
- name: end_date_gte
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: End Date Gte
- name: end_date_gt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: End Date Gt
- name: end_date_lte
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: End Date Lte
- name: end_date_lt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: End Date Lt
responses:
'200':
description: Successful Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@

from __future__ import annotations

from typing import Annotated

from fastapi import Depends, HTTPException, status
from sqlalchemy import or_, select

from airflow.api_fastapi.auth.managers.models.resource_details import DagAccessEntity
from airflow.api_fastapi.common.dagbag import DagBagDep
from airflow.api_fastapi.common.db.common import SessionDep
from airflow.api_fastapi.common.parameters import RangeFilter, datetime_range_filter_factory
from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.datamodels.task_instances import LoopIterationResponse
from airflow.api_fastapi.core_api.datamodels.ui.gantt import GanttResponse, GanttTaskInstance
from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
from airflow.api_fastapi.core_api.security import requires_access_dag
from airflow.models.dagrun import DagRun
from airflow.models.task_coordinates import TaskCoordinateResolver, public_map_index_expression
from airflow.models.taskinstance import TaskInstance
from airflow.utils.state import TaskInstanceState
Expand Down Expand Up @@ -60,6 +64,10 @@
def get_gantt_data(
dag_id: str,
run_id: str,
start_date_range: Annotated[
RangeFilter, Depends(datetime_range_filter_factory("start_date", TaskInstance))
],
end_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("end_date", TaskInstance))],
session: SessionDep,
dag_bag: DagBagDep,
) -> GanttResponse:
Expand Down Expand Up @@ -97,14 +105,22 @@ def get_gantt_data(
# loses each earlier try the moment a clear archives it -- including the attempt the
# filter above drops the pending retry in favour of.
).execution_options(include_all_attempts=True)
query = start_date_range.to_orm(query)
query = end_date_range.to_orm(query)

results = session.execute(query).fetchall()

if not results:
raise HTTPException(
status.HTTP_404_NOT_FOUND,
f"No task instances for dag_id={dag_id} run_id={run_id}",
)
filtered_existing_run = (
start_date_range.is_active() or end_date_range.is_active()
) and session.scalar(
select(DagRun.run_id).where(DagRun.dag_id == dag_id, DagRun.run_id == run_id)
) is not None
if not filtered_existing_run:
raise HTTPException(
status.HTTP_404_NOT_FOUND,
f"No task instances for dag_id={dag_id} run_id={run_id}",
)

resolver = TaskCoordinateResolver(dag_bag, session)
resolver.prefetch_regions(results)
Expand Down
12 changes: 10 additions & 2 deletions airflow-core/src/airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,10 +1249,18 @@ export const UseGridServiceGetLoopHistoryKeyFn = ({ dagId, groupId, limit }: {
export type GanttServiceGetGanttDataDefaultResponse = Awaited<ReturnType<typeof GanttService.getGanttData>>;
export type GanttServiceGetGanttDataQueryResult<TData = GanttServiceGetGanttDataDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useGanttServiceGetGanttDataKey = "GanttServiceGetGanttData";
export const UseGanttServiceGetGanttDataKeyFn = ({ dagId, runId }: {
export const UseGanttServiceGetGanttDataKeyFn = ({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }: {
dagId: string;
endDateGt?: string;
endDateGte?: string;
endDateLt?: string;
endDateLte?: string;
runId: string;
}, queryKey?: Array<unknown>) => [useGanttServiceGetGanttDataKey, ...(queryKey ?? [{ dagId, runId }])];
startDateGt?: string;
startDateGte?: string;
startDateLt?: string;
startDateLte?: string;
}, queryKey?: Array<unknown>) => [useGanttServiceGetGanttDataKey, ...(queryKey ?? [{ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }])];
export type CalendarServiceGetCalendarDefaultResponse = Awaited<ReturnType<typeof CalendarService.getCalendar>>;
export type CalendarServiceGetCalendarQueryResult<TData = CalendarServiceGetCalendarDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useCalendarServiceGetCalendarKey = "CalendarServiceGetCalendar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2476,13 +2476,29 @@ export const ensureUseGridServiceGetLoopHistoryData = (queryClient: QueryClient,
* @param data The data for the request.
* @param data.dagId
* @param data.runId
* @param data.startDateGte
* @param data.startDateGt
* @param data.startDateLte
* @param data.startDateLt
* @param data.endDateGte
* @param data.endDateGt
* @param data.endDateLte
* @param data.endDateLt
* @returns GanttResponse Successful Response
* @throws ApiError
*/
export const ensureUseGanttServiceGetGanttDataData = (queryClient: QueryClient, { dagId, runId }: {
export const ensureUseGanttServiceGetGanttDataData = (queryClient: QueryClient, { dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }: {
dagId: string;
endDateGt?: string;
endDateGte?: string;
endDateLt?: string;
endDateLte?: string;
runId: string;
}) => queryClient.ensureQueryData({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, runId }), queryFn: () => GanttService.getGanttData({ dagId, runId }) });
startDateGt?: string;
startDateGte?: string;
startDateLt?: string;
startDateLte?: string;
}) => queryClient.ensureQueryData({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }), queryFn: () => GanttService.getGanttData({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }) });
/**
* Get Calendar
* Get calendar data for a Dag including historical and planned Dag runs.
Expand Down
20 changes: 18 additions & 2 deletions airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2476,13 +2476,29 @@ export const prefetchUseGridServiceGetLoopHistory = (queryClient: QueryClient, {
* @param data The data for the request.
* @param data.dagId
* @param data.runId
* @param data.startDateGte
* @param data.startDateGt
* @param data.startDateLte
* @param data.startDateLt
* @param data.endDateGte
* @param data.endDateGt
* @param data.endDateLte
* @param data.endDateLt
* @returns GanttResponse Successful Response
* @throws ApiError
*/
export const prefetchUseGanttServiceGetGanttData = (queryClient: QueryClient, { dagId, runId }: {
export const prefetchUseGanttServiceGetGanttData = (queryClient: QueryClient, { dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }: {
dagId: string;
endDateGt?: string;
endDateGte?: string;
endDateLt?: string;
endDateLte?: string;
runId: string;
}) => queryClient.prefetchQuery({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, runId }), queryFn: () => GanttService.getGanttData({ dagId, runId }) });
startDateGt?: string;
startDateGte?: string;
startDateLt?: string;
startDateLte?: string;
}) => queryClient.prefetchQuery({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }), queryFn: () => GanttService.getGanttData({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }) });
/**
* Get Calendar
* Get calendar data for a Dag including historical and planned Dag runs.
Expand Down
20 changes: 18 additions & 2 deletions airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2476,13 +2476,29 @@ export const useGridServiceGetLoopHistory = <TData = Common.GridServiceGetLoopHi
* @param data The data for the request.
* @param data.dagId
* @param data.runId
* @param data.startDateGte
* @param data.startDateGt
* @param data.startDateLte
* @param data.startDateLt
* @param data.endDateGte
* @param data.endDateGt
* @param data.endDateLte
* @param data.endDateLt
* @returns GanttResponse Successful Response
* @throws ApiError
*/
export const useGanttServiceGetGanttData = <TData = Common.GanttServiceGetGanttDataDefaultResponse, TError = unknown, TQueryKey extends Array<unknown> = unknown[]>({ dagId, runId }: {
export const useGanttServiceGetGanttData = <TData = Common.GanttServiceGetGanttDataDefaultResponse, TError = unknown, TQueryKey extends Array<unknown> = unknown[]>({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }: {
dagId: string;
endDateGt?: string;
endDateGte?: string;
endDateLt?: string;
endDateLte?: string;
runId: string;
}, queryKey?: TQueryKey, options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">) => useQuery<TData, TError>({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, runId }, queryKey), queryFn: () => GanttService.getGanttData({ dagId, runId }) as TData, ...options });
startDateGt?: string;
startDateGte?: string;
startDateLt?: string;
startDateLte?: string;
}, queryKey?: TQueryKey, options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">) => useQuery<TData, TError>({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }, queryKey), queryFn: () => GanttService.getGanttData({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }) as TData, ...options });
/**
* Get Calendar
* Get calendar data for a Dag including historical and planned Dag runs.
Expand Down
20 changes: 18 additions & 2 deletions airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2476,13 +2476,29 @@ export const useGridServiceGetLoopHistorySuspense = <TData = Common.GridServiceG
* @param data The data for the request.
* @param data.dagId
* @param data.runId
* @param data.startDateGte
* @param data.startDateGt
* @param data.startDateLte
* @param data.startDateLt
* @param data.endDateGte
* @param data.endDateGt
* @param data.endDateLte
* @param data.endDateLt
* @returns GanttResponse Successful Response
* @throws ApiError
*/
export const useGanttServiceGetGanttDataSuspense = <TData = Common.GanttServiceGetGanttDataDefaultResponse, TError = unknown, TQueryKey extends Array<unknown> = unknown[]>({ dagId, runId }: {
export const useGanttServiceGetGanttDataSuspense = <TData = Common.GanttServiceGetGanttDataDefaultResponse, TError = unknown, TQueryKey extends Array<unknown> = unknown[]>({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }: {
dagId: string;
endDateGt?: string;
endDateGte?: string;
endDateLt?: string;
endDateLte?: string;
runId: string;
}, queryKey?: TQueryKey, options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">) => useSuspenseQuery<TData, TError>({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, runId }, queryKey), queryFn: () => GanttService.getGanttData({ dagId, runId }) as TData, ...options });
startDateGt?: string;
startDateGte?: string;
startDateLt?: string;
startDateLte?: string;
}, queryKey?: TQueryKey, options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">) => useSuspenseQuery<TData, TError>({ queryKey: Common.UseGanttServiceGetGanttDataKeyFn({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }, queryKey), queryFn: () => GanttService.getGanttData({ dagId, endDateGt, endDateGte, endDateLt, endDateLte, runId, startDateGt, startDateGte, startDateLt, startDateLte }) as TData, ...options });
/**
* Get Calendar
* Get calendar data for a Dag including historical and planned Dag runs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5844,6 +5844,14 @@ export class GanttService {
* @param data The data for the request.
* @param data.dagId
* @param data.runId
* @param data.startDateGte
* @param data.startDateGt
* @param data.startDateLte
* @param data.startDateLt
* @param data.endDateGte
* @param data.endDateGt
* @param data.endDateLte
* @param data.endDateLt
* @returns GanttResponse Successful Response
* @throws ApiError
*/
Expand All @@ -5855,6 +5863,16 @@ export class GanttService {
dag_id: data.dagId,
run_id: data.runId
},
query: {
start_date_gte: data.startDateGte,
start_date_gt: data.startDateGt,
start_date_lte: data.startDateLte,
start_date_lt: data.startDateLt,
end_date_gte: data.endDateGte,
end_date_gt: data.endDateGt,
end_date_lte: data.endDateLte,
end_date_lt: data.endDateLt
},
errors: {
404: 'Not Found',
422: 'Validation Error'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5610,7 +5610,15 @@ export type GetLoopHistoryResponse = LoopHistoryResponse;

export type GetGanttDataData = {
dagId: string;
endDateGt?: string | null;
endDateGte?: string | null;
endDateLt?: string | null;
endDateLte?: string | null;
runId: string;
startDateGt?: string | null;
startDateGte?: string | null;
startDateLt?: string | null;
startDateLte?: string | null;
};

export type GetGanttDataResponse = GanttResponse;
Expand Down
Loading
Loading