Airflow 2.7.3中HttpSensor任务持续处于Running状态求助
Airflow 2.7.3 HttpSensor任务卡在Running状态排查方案
问题场景
- 新安装Airflow 2.7.3,采用默认配置(SQLite元数据库 + SequentialExecutor)
- DAG中第一个
create_table(PostgresOperator)任务执行成功 - 后续
is_api_available(HttpSensor)任务持续卡在running状态 - 该DAG在Docker容器环境中可正常运行,仅本地默认配置环境出现问题
关键日志信息(已翻译)
[2024-02-17T21:15:11.582-0600] {scheduler_job_runner.py:722} INFO - 任务实例完成: dag_id=user_processing, task_id=create_table, run_id=scheduled__2024-02-17T00:00:00+00:00, map_index=-1, run_start_date=2024-02-18 03:15:10.523261+00:00, run_end_date=2024-02-18 03:15:11.128272+00:00, run_duration=0.605011, state=success, executor_state=success, try_number=1, max_tries=0, job_id=49, pool=default_pool, queue=default, priority_weight=5, operator=PostgresOperator, queued_dttm=2024-02-18 03:15:06.785081+00:00, queued_by_job_id=48, pid=26667 [2024-02-17T21:15:11.660-0600] {scheduler_job_runner.py:413} INFO - 有1个任务等待执行: <TaskInstance: user_processing.is_api_available scheduled__2024-02-17T00:00:00+00:00 [scheduled]> [2024-02-17T21:15:11.660-0600] {scheduler_job_runner.py:476} INFO - DAG user_processing 当前有0/16个运行中和排队中的任务 [2024-02-17T21:15:11.660-0600] {scheduler_job_runner.py:592} INFO - 将以下任务设置为排队状态: <TaskInstance: user_processing.is_api_available scheduled__2024-02-17T00:00:00+00:00 [scheduled]> [2024-02-17T21:15:11.661-0600] {taskinstance.py:1441} WARNING - 无法记录任务is_api_available的scheduled_duration,因为未保存之前的状态变更时间 [2024-02-17T21:15:11.661-0600] {scheduler_job_runner.py:635} INFO - 将TaskInstanceKey(dag_id='user_processing', task_id='is_api_available', run_id='scheduled__2024-02-17T00:00:00+00:00', try_number=1, map_index=-1)发送到执行器,优先级4,队列default [2024-02-17T21:15:11.662-0600] {base_executor.py:146} INFO - 添加到队列: ['airflow', 'tasks', 'run', 'user_processing', 'is_api_available', 'scheduled__2024-02-17T00:00:00+00:00', '--local', '--subdir', 'DAGS_FOLDER/user_processing.py'] [2024-02-17T21:15:11.665-0600] {sequential_executor.py:74} INFO - 执行命令: ['airflow', 'tasks', 'run', 'user_processing', 'is_api_available', 'scheduled__2024-02-17T00:00:00+00:00', '--local', '--subdir', 'DAGS_FOLDER/user_processing.py'] [2024-02-17T21:15:12.746-0600] {dagbag.py:536} INFO - 从/Users/jacobdol/Documents/airflow/dags/user_processing.py加载DagBag [2024-02-17T21:15:14.274-0600] {task_command.py:416} INFO - 在主机jacobs-air.lan上运行<TaskInstance: user_processing.is_api_available scheduled__2024-02-17T00:00:00+00:00 [queued]>
排查与解决步骤
1. 验证目标API的本地可达性
直接在Airflow所在主机执行curl命令测试API:
curl -v <你的HttpSensor配置的API地址>
确认是否能返回预期状态码,本地环境可能存在代理、防火墙限制,导致无法访问目标API(容器环境无此限制)。
2. 检查HttpSensor参数配置
- 临时修改HttpSensor的
timeout参数为较小值(如30秒),验证任务是否会触发失败,确认任务是否在持续尝试连接。 - 检查
poke_interval设置,若间隔过大也会导致任务长时间显示running。
3. 修复SQLite数据库状态一致性
日志中的警告提示元数据库状态异常,可按以下步骤修复:
- 停止Airflow服务:
airflow scheduler stop airflow webserver stop - 备份默认路径下的SQLite数据库:
~/airflow/airflow.db - 重置并重新初始化数据库(仅测试环境操作):
airflow db reset -y airflow db init - 重启Airflow服务:
airflow scheduler start airflow webserver start
4. 确认本地依赖完整性
- 检查是否安装HttpSensor所需的依赖包:
pip install requests - 对比Docker与本地环境的Python版本、Airflow依赖版本,确保一致:
pip freeze | grep airflow pip freeze | grep requests
5. 获取详细任务日志
手动运行任务并开启DEBUG日志,查看具体错误:
airflow tasks run user_processing is_api_available scheduled__2024-02-17T00:00:00+00:00 --local --subdir DAGS_FOLDER/user_processing.py -l DEBUG
内容的提问来源于stack exchange,提问作者Jacob
相关产品推荐
相关产品推荐

