tirkarthi opened a new pull request, #38214:
URL: https://github.com/apache/airflow/pull/38214

   Add average duration for run and queued time in task duration and dag run 
duration. This can help in visualizing potential delays in runs like below dag 
for one month where there is more sleep time in the last 5 days compared to 
previous days.
   
   Related: #22132
   Ref comment in PR review : 
https://github.com/apache/airflow/pull/35863#issuecomment-1894981925
   
   
![image](https://github.com/apache/airflow/assets/3972343/ff79d5b0-e205-4c88-8483-c2b52c314dc1)
   
   
![image](https://github.com/apache/airflow/assets/3972343/a7ef78b8-a44a-4270-8ae3-94aa24ed05ed)
   
   
   ```python
   from datetime import datetime, timedelta
   
   from airflow import DAG
   from airflow.decorators import task
   from airflow.operators.empty import EmptyOperator
   
   from datetime import timedelta
   
   
   with DAG(
       dag_id="task_duration_average",
       start_date=datetime(2024, 1, 1),
       end_date=datetime(2024, 1, 31),
       catchup=True,
       schedule_interval="@daily",
   ) as dag:
   
       @task
       def sleeper(ds=None):
           import random, time, pendulum
   
           end_term = pendulum.datetime(2024, 1, 25)
           execution_date = pendulum.parse(ds)
   
           if execution_date < end_term:
               duration = random.randint(1, 5)
           else:
               duration = random.randint(10, 20)
   
           time.sleep(duration)
   
       sleeper()
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to