How to use Timezone in Airflow

Derry Berni Cahyady
1 min readNov 22, 2019

--

Hello, Good People

I recommend this repo because very easy to config :

https://github.com/puckel/docker-airflow

if you use docker-compose you must set localtime same as your host

volumes:
- "/etc/localtime:/etc/localtime:ro"

This example code :

from airflow.operators import PythonOperator
from airflow.models import DAG
from datetime import datetime, timedelta
import pendulum
args = {
'owner': 'airflow',
'email_on_failure': True,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
'depends_on_past': False,
}
# Set-up DAG
test_dag = DAG(
dag_id='motherv6',
start_date=pendulum.datetime(year=2019, month=4, day=4, tzinfo='Asia/Jakarta'),
schedule_interval='28 14 * * *',
catchup=False,
default_args=args
)
# modelling
def modelling(**kwargs):
print('Now ?')
print(datetime.datetime.now())
getDailyTask = PythonOperator(
task_id='get-daily',
python_callable=modelling,
dag=test_dag)
# Check initial schedule
execution_date = test_dag.start_date
test_dag.following_schedule(execution_date)
getDailyTask

Thankyou.

--

--

Derry Berni Cahyady
Derry Berni Cahyady

Written by Derry Berni Cahyady

Data & Security Enthusiast | Software Engineer

No responses yet