You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from airflow import DAG
|
|
from airflow.operators.http_operator import SimpleHttpOperator
|
|
from datetime import datetime, timedelta
|
|
from airflow.utils.dates import days_ago
|
|
|
|
default_args = {
|
|
'owner': 'airflow',
|
|
'depends_on_past': False,
|
|
'email_on_failure': False,
|
|
'email_on_retry': False,
|
|
'retries': 1,
|
|
'retry_delay': timedelta(minutes=5),
|
|
}
|
|
|
|
with DAG(
|
|
'daily_efficiency_api_calls',
|
|
default_args=default_args,
|
|
description='Efficiency API calls at specific times',
|
|
schedule_interval='30 0,8,15 * * *', # 07:30, 15:30, 22:30 GMT+7
|
|
start_date=days_ago(1),
|
|
tags=['api', 'efficiency'],
|
|
) as dag:
|
|
|
|
# Morning call at 07:30 GMT+7 (00:30 UTC)
|
|
morning_api_call = SimpleHttpOperator(
|
|
task_id='morning_api_call',
|
|
http_conn_id='efficiency_api',
|
|
endpoint='efficiency/data/auto', # No need to include the base URL
|
|
method='GET',
|
|
)
|
|
|
|
# Afternoon call at 15:30 GMT+7 (08:30 UTC)
|
|
afternoon_api_call = SimpleHttpOperator(
|
|
task_id='afternoon_api_call',
|
|
http_conn_id='efficiency_api',
|
|
endpoint='efficiency/data/auto',
|
|
method='GET',
|
|
)
|
|
|
|
# Night call at 22:30 GMT+7 (15:30 UTC)
|
|
night_api_call = SimpleHttpOperator(
|
|
task_id='night_api_call',
|
|
http_conn_id='efficiency_api',
|
|
endpoint='efficiency/data/auto',
|
|
method='GET',
|
|
)
|