簡體   English   中英

使用語句超時運行 postgres 運算符 airflow dag

[英]Run postgres operator with statement timeout airflow dag

所以我一直在嘗試在我的 DAG 上運行 2 個 postgres 運算符,看起來像這樣:

default_args = {
    'owner': 'local',
}

log = logging.getLogger(_name_)

TEMP_SETTLEMENT ="""
set statement_timeout to 0;
select function_a();
"""

VACUM_SETTLEMENT="""
vacuum (verbose, analyze) test_table;
"""

try:
    with DAG(
        dag_id='temp-test',
        default_args=default_args,
        schedule_interval=none,
        start_date=datetime(2021, 10, 1),
        max_active_runs=1,
        catchup=False
    ) as dag:

        pg = PostgresOperator(
            task_id="data",
            postgres_conn_id="connection_1",
            database="DB_test",
            autocommit=True,
            sql=TEMP_SETTLEMENT,
        )

        vacum = PostgresOperator(
            task_id="vacum",
            postgres_conn_id="connection_1",
            database="DB_test",
            autocommit=True,
            sql=VACUM_SETTLEMENT,    )

        pg >> vacum 

except ImportError as e:
    log.warning("Could not import DAGs: %s", str(e))

當我嘗試運行 temp_settlement 時,我總是收到語句超時,有什么辦法可以保持 statement_timeout=0 嗎?

謝謝

更新:

啟動apache-airflow-providers-postgres>=4.1.0你可以這樣做:

PostgresOperator(
...,
runtime_parameters={'statement_timeout': '3000ms'},
)

在解決問題PR中添加了此功能。

原答案:

你沒有從你的描述中提到它我假設超時來自 Postgres 而不是來自 Airflow。

目前PostgresOperator不允許覆蓋掛鈎/連接設置。 要解決您的問題,您需要按照文檔中的說明在額外字段中編輯connection_1 ,您需要添加statement_timeout

{'statement_timeout': '3600s'}

我打開https://github.com/apache/airflow/issues/21486作為后續功能請求,以允許直接從操作員設置statement_timeout

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM