Fix Task Duration Calculation & Display#23173
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
|
hi @aschoe21 could you include a screenshot of the functionality working as well? |
Sure, here's a screenshot of the tooltip showing a task completing in 0.105Sec |
319f921 to
9e16b0c
Compare
9e16b0c to
da586f6
Compare
|
Would the decimal places always show, even when the duration is long? Ideally I’d only want them when the duration is <1 and not if it’s e.g. 105.378 seconds. |
Yes, and this also breaks down when duration is better shown as minutes, hours or even days. Overall, how we display durations in the UI is inconsistent and we should consolidate down to one format. I was playing around with that here: https://github.com/apache/airflow/pull/22996/files What do you think of choosing the most important unit and then limiting to just 1-2 decimal places: |
|
I think if it's in to minutes or hours then |
bbovenzi
left a comment
There was a problem hiding this comment.
Let's update convertSecondsToHumanReadable in main.js:
- Only show decimal if seconds is less than 1
- If decimal is also 0, then lets return
<1ms - Switch
Hours->h,Min->m,Sec->s
I think with those changes this should be good to merge. Then we can update the rest of the UI and webserver to make sure duration is always displayed consistently.
|
@aschoe21 are you still working on this PR? |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |



closes: #23169
Prevent moment from truncating the result of diff to zero decimal places
As moment.diff has the default behavior of truncating the decimal places of diff results (i.e. rounding down to the nearest integer), when the duration of a task run is less than a full second moment rounds the duration down to 0. This behavior results in the task duration rendering as empty/null rather than as the correct task run duration.
Moment's diff function accepts a third, optional boolean argument that dictates its result truncation behavior. By default this value is false which leads to the unwanted behavior described above. Setting this argument to true when calling diff will allow the result to exist as a decimal, fixing the situation where task run duration is rounded down to 0 seconds.