Cloud Composer Airflow任务失败,但功能成功完成

时间:2019-02-27 22:06:17

标签: python google-cloud-platform airflow google-cloud-composer

我正在尝试使用Cloud Composer编写我的第一个Airflow作业。我的DAG有三个任务,第一个任务成功完成,但是第二个任务似乎失败,并发出任何故障错误消息。我在第二个任务中使用019-02-27T17:03:41.637-0800 DEBUG [input] file/states.go:68 New state added for /logs/api.log 2019-02-27T17:03:41.637-0800 DEBUG [registrar] registrar/registrar.go:315 Registrar state updates processed. Count: 1 2019-02-27T17:03:41.637-0800 DEBUG [registrar] registrar/registrar.go:400 Write registry file: /filebeat/registry 2019-02-27T17:03:41.637-0800 INFO log/harvester.go:255 Harvester started for file: /logs/api.log 2019-02-27T17:03:41.647-0800 DEBUG [publish] pipeline/processor.go:308 Publish event: { "@timestamp": "2019-02-28T01:03:41.647Z", "@metadata": { "beat": "filebeat", "type": "doc", "version": "6.6.0" }, "log": { "file": { "path": "/logs/api.log" } }, "input": { "type": "log" }, "host": { "name": "tomcat", "os": { "family": "redhat", "name": "CentOS Linux", "codename": "Core", "platform": "centos", "version": "7 (Core)" }, "id": "6aaed308aa5a419f880c5e45eea65414", "containerized": true, "architecture": "x86_64" }, "meta": { "cloud": { "region": "CanadaCentral", "provider": "az", "instance_id": "6452bcf4-7f5d-4fc3-9f8e-5ea57f00724b", "instance_name": "tomcat", "machine_type": "Standard_D8s_v3" } }, "message": "2018-09-14 20:23:37 INFO ContextLoader:272 - Root WebApplicationContext: initialization started", "source": "/logs/api.log", "offset": 0, "prospector": { "type": "log" }, "beat": { "hostname": "tomcat", "version": "6.6.0", "name": "tomcat" } } 。被调用的函数执行长时间运行的查询并轮询直到查询完成。查询完成后,我会收到一条消息,指出数据已输出到正确的表中,但是随后Airflow将任务视为失败并再次重试该任务。

我的PythonOperator for DAG看起来像这样:

default_args

编辑:

这是我的Python可调用和PythonOperator。 default_args = { 'owner': 'airflow', 'depends_on_past': False, 'start_date': today.strftime("%Y-%m-%d"), 'email': ['email@email.com'], 'email_on_failure': True, 'email_on_retry': False, 'retries': 1, 'retry_delay': timedelta(minutes=1), 'dagrun_timeout': timedelta(minutes=30) } 调用在Stackdriver日志中产生输出,并指示实际功能已完成,但任务失败。

run_query

我将不胜感激任何提示!

2 个答案:

答案 0 :(得分:0)

我在您的代码中看不到任何错误处理。

长时间运行的查询和轮询失败时,引发AirflowException,这将导致任务立即移至失败状态。

from airflow import AirflowException

ValueError可用于失败并重试

答案 1 :(得分:0)

我在 GCP Cloud Composer [composer-1.11.0-airflow-1.10.9] 中遇到了同样的问题。

对于长时间运行的任务,很有可能(尤其是在使用 KubernetesPodOperator 时)任务被 Airflow Scheduler 标记为 Zombie。

解决方案:-

我将调度程序中的 scheduler_zombie_task_threshold 配置参数值从 300(默认 5 分钟)增加到 1800(30 分钟)。在此之后,我能够运行任务长达 45 分钟,并且不会以失败状态结束。

如何更改参数 -

  1. 转到 GCP 云控制台。
  2. 导航到 Composer。
  3. 打开作曲家。
  4. 转到气流配置覆盖选项卡
  5. 输入值: 调度程序 scheduler_zombie_task_threshold 1800