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

Add dry run for backfill #45062

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
13 changes: 13 additions & 0 deletions airflow/api_fastapi/core_api/datamodels/backfills.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,16 @@ class BackfillCollectionResponse(BaseModel):

backfills: list[BackfillResponse]
total_entries: int


class DryRunBackfillResponse(BaseModel):
"""Data model for run information during a backfill operation."""
prabhusneha marked this conversation as resolved.
Show resolved Hide resolved

logical_date: datetime
pierrejeambrun marked this conversation as resolved.
Show resolved Hide resolved


class DryRunBackfillCollectionResponse(BaseModel):
"""Serializer for responses in dry-run mode for backfill operations."""
prabhusneha marked this conversation as resolved.
Show resolved Hide resolved

backfills: list[DryRunBackfillResponse]
total_entries: int
76 changes: 76 additions & 0 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,55 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/backfills/dry_run:
post:
tags:
- Backfill
summary: Create Backfill Dry Run
operationId: create_backfill_dry_run
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/BackfillPostBody'
required: true
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/DryRunBackfillCollectionResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'404':
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'409':
description: Conflict
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/connections/{connection_id}:
delete:
tags:
Expand Down Expand Up @@ -7912,6 +7961,33 @@ components:
This is the set of allowable values for the ``warning_type`` field

in the DagWarning model.'
DryRunBackfillCollectionResponse:
properties:
backfills:
items:
$ref: '#/components/schemas/DryRunBackfillResponse'
type: array
title: Backfills
total_entries:
type: integer
title: Total Entries
type: object
required:
- backfills
- total_entries
title: DryRunBackfillCollectionResponse
description: Serializer for responses in dry-run mode for backfill operations.
DryRunBackfillResponse:
properties:
logical_date:
type: string
format: date-time
title: Logical Date
type: object
required:
- logical_date
title: DryRunBackfillResponse
description: Data model for run information during a backfill operation.
EdgeResponse:
properties:
is_setup_teardown:
Expand Down
39 changes: 39 additions & 0 deletions airflow/api_fastapi/core_api/routes/public/backfills.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
BackfillCollectionResponse,
BackfillPostBody,
BackfillResponse,
DryRunBackfillCollectionResponse,
DryRunBackfillResponse,
)
from airflow.api_fastapi.core_api.openapi.exceptions import (
create_openapi_http_exception_doc,
Expand Down Expand Up @@ -206,3 +208,40 @@ def create_backfill(
status_code=status.HTTP_409_CONFLICT,
detail=f"There is already a running backfill for dag {backfill_request.dag_id}",
)


@backfills_router.post(
path="/dry_run",
responses=create_openapi_http_exception_doc(
[
status.HTTP_404_NOT_FOUND,
status.HTTP_409_CONFLICT,
]
),
)
def create_backfill_dry_run(
body: BackfillPostBody,
) -> DryRunBackfillCollectionResponse:
from_date = timezone.coerce_datetime(body.from_date)
to_date = timezone.coerce_datetime(body.to_date)

try:
backfills_dry_run = _create_backfill(
dag_id=body.dag_id,
from_date=from_date,
to_date=to_date,
max_active_runs=body.max_active_runs,
reverse=body.run_backwards,
dag_run_conf=body.dag_run_conf,
reprocess_behavior=body.reprocess_behavior,
dry_run=True,
)
backfills = [DryRunBackfillResponse(logical_date=logical_date) for logical_date in backfills_dry_run]
prabhusneha marked this conversation as resolved.
Show resolved Hide resolved

return DryRunBackfillCollectionResponse(backfills=backfills, total_entries=len(backfills_dry_run))

except AlreadyRunningBackfill:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="There is already a running backfill for the dag",
)
Loading