airflow - 如何为 Apache Airflow DAG 定义超时?
问题描述
我正在使用 Airflow 1.10.2,但 Airflow 似乎忽略了我为 DAG 设置的超时。
我正在使用dagrun_timeout
参数(例如 20 秒)为 DAG 设置超时时间,并且我有一个需要 2 分钟才能运行的任务,但 Airflow 将 DAG 标记为成功!
args = {
'owner': 'me',
'start_date': airflow.utils.dates.days_ago(2),
'provide_context': True,
}
dag = DAG(
'test_timeout',
schedule_interval=None,
default_args=args,
dagrun_timeout=timedelta(seconds=20),
)
def this_passes(**kwargs):
return
def this_passes_with_delay(**kwargs):
time.sleep(120)
return
would_succeed = PythonOperator(
task_id='would_succeed',
dag=dag,
python_callable=this_passes,
email=to,
)
would_succeed_with_delay = PythonOperator(
task_id='would_succeed_with_delay',
dag=dag,
python_callable=this_passes_with_delay,
email=to,
)
would_succeed >> would_succeed_with_delay
不会抛出任何错误消息。我是否使用了不正确的参数?
解决方案
如源代码中所述:
:param dagrun_timeout: specify how long a DagRun should be up before
timing out / failing, so that new DagRuns can be created. The timeout
is only enforced for scheduled DagRuns, and only once the
# of active DagRuns == max_active_runs.
所以这可能是您设置时的预期行为schedule_interval=None
。这里的想法是确保计划的 DAG 不会永远持续并阻止后续运行实例。
现在,您可能对execution_timeout
可用的所有运算符感兴趣。例如,您可以PythonOperator
像这样设置 60 秒超时:
would_succeed_with_delay = PythonOperator(task_id='would_succeed_with_delay',
dag=dag,
execution_timeout=timedelta(seconds=60),
python_callable=this_passes_with_delay,
email=to)
推荐阅读
- json - 在 bat 文件中解析 JSON
- javascript - 如何在javascript代码中访问从服务器发送的数据(使用flask)?
- uml - 需要帮助创建用例图
- reactjs - 当 eslint 指责 max-length 并且 .prettierignore 不起作用时 Prettier 不适用
- go - go 模块可以没有 go.mod 文件吗?
- solidity - 如何在合同扫描页面中显示网站?
- numbers - 使用 Visual Studio 和 conda 环境的交互式窗口中未显示编辑窗口的行号
- scala - ReactiveMongo 0.20.12-Play28 在启动时因 MatchError 崩溃:成功异常
- javascript - 无法将反应组件导入 gatsby 启动组件
- c# - 将句子开头的每个单词大写。一个字符串中的多个句子。视觉 C#