airflow cronjob timezone 设置

警告
本文最后更新于 2023-05-19,文中内容可能已过时。

修改 airflow 默认的时区

修改 airflow.cfg 配置

1
2
sed -i "s|^default_timezone = .*|default_timezone = Asia/Shanghai|g"        airflow.cfg
sed -i "s|^default_ui_timezone = .*|default_ui_timezone = Asia/Shanghai|g"  airflow.cfg

DAG 设定时区

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from docker.types import Mount
from airflow import DAG
from airflow.utils.dates import days_ago
from airflow.decorators import task
from airflow.operators.bash import BashOperator
from airflow.operators.python import PythonOperator
from airflow.providers.docker.operators.docker import DockerOperator
from wepy.utils.init import *

import pendulum
local_tz = pendulum.timezone("Asia/Shanghai") ## 设置时区
DEFAULT_ARGS = {
    'owner'            : 'william',
    'email'            : 'lfang@wuyacapital.com',
    'email_on_failure' : False,
    'email_on_retry'   : False,
    'retries'          : 3,
    'retry_delay'      : timedelta(minutes=1)
}

with DAG(
    dag_id         = "pretrading.all.csv",
    default_args   = DEFAULT_ARGS,
    schedule       = "35 08,20 * * 1-5",
    start_date     = datetime(2023, 1, 1, tzinfo=local_tz), ## 指定时区
    catchup        = False,
    dagrun_timeout = timedelta(seconds=60*3),
    tags           = ['pretrading', 'all.csv'],
) as dag:

相关内容

william 支付宝支付宝
william 微信微信
0%