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
36 changes: 36 additions & 0 deletions airflow-core/src/airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,42 @@ workers:
sensitive: true
example: ~
default: ""
min_heartbeat_interval:
description: |
The minimum interval (in seconds) at which the worker checks the task instance's
heartbeat status with the API server to confirm it is still alive.
version_added: 3.0.0
type: integer
example: ~
default: "5"
max_failed_heartbeats:
description: |
The maximum number of consecutive failed heartbeats before terminating the task instance process.
version_added: 3.0.0
type: integer
example: ~
default: "3"
execution_api_retries:
description: |
The maximum number of retry attempts to the execution API server.
version_added: 3.0.0
type: integer
example: ~
default: "5"
execution_api_retry_wait_min:
description: |
The minimum amount of time (in seconds) to wait before retrying a failed API request.
version_added: 3.0.0
type: float
example: ~
default: "1.0"
execution_api_retry_wait_max:
description: |
The maximum amount of time (in seconds) to wait before retrying a failed API request.
version_added: 3.0.0
type: float
example: ~
default: "90.0"
api_auth:
description: Settings relating to authentication on the Airflow APIs
options:
Expand Down
11 changes: 4 additions & 7 deletions task-sdk/src/airflow/sdk/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from __future__ import annotations

import logging
import os
import sys
import uuid
from http import HTTPStatus
Expand All @@ -32,6 +31,7 @@
from tenacity import before_log, wait_random_exponential
from uuid6 import uuid7

from airflow.configuration import conf
from airflow.sdk import __version__
from airflow.sdk.api.datamodels._generated import (
API_VERSION,
Expand Down Expand Up @@ -489,13 +489,10 @@ def noop_handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(200, json={"text": "Hello, world!"})


# Config options for SDK how retries on HTTP requests should be handled
# Note: Given defaults make attempts after 1, 3, 7, 15 and fails after 31seconds
# So far there is no other config facility in SDK we use ENV for the moment
# TODO: Consider these env variables while handling airflow confs in task sdk
API_RETRIES = int(os.getenv("AIRFLOW__WORKERS__API_RETRIES", 5))
API_RETRY_WAIT_MIN = float(os.getenv("AIRFLOW__WORKERS__API_RETRY_WAIT_MIN", 1.0))
API_RETRY_WAIT_MAX = float(os.getenv("AIRFLOW__WORKERS__API_RETRY_WAIT_MAX", 90.0))
API_RETRIES = conf.getint("workers", "execution_api_retries")
API_RETRY_WAIT_MIN = conf.getfloat("workers", "execution_api_retry_wait_min")
API_RETRY_WAIT_MAX = conf.getfloat("workers", "execution_api_retry_wait_max")


class Client(httpx.Client):
Expand Down
10 changes: 4 additions & 6 deletions task-sdk/src/airflow/sdk/execution_time/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import structlog
from pydantic import TypeAdapter

from airflow.configuration import conf
from airflow.sdk.api.client import Client, ServerResponseError
from airflow.sdk.api.datamodels._generated import (
AssetResponse,
Expand Down Expand Up @@ -109,13 +110,10 @@

log: FilteringBoundLogger = structlog.get_logger(logger_name="supervisor")

# TODO: Pull this from config
# (previously `[scheduler] task_instance_heartbeat_sec` with the following as fallback if it is 0:
# `[scheduler] task_instance_heartbeat_timeout`)
HEARTBEAT_TIMEOUT: int = 30
HEARTBEAT_TIMEOUT: int = conf.getint("scheduler", "task_instance_heartbeat_timeout")
# Don't heartbeat more often than this
MIN_HEARTBEAT_INTERVAL: int = 5
MAX_FAILED_HEARTBEATS: int = 3
MIN_HEARTBEAT_INTERVAL: int = conf.getint("workers", "min_heartbeat_interval")
MAX_FAILED_HEARTBEATS: int = conf.getint("workers", "max_failed_heartbeats")

# These are the task instance states that require some additional information to transition into.
# "Directly" here means that the PATCH API calls to transition into these states are
Expand Down