This is an automated email from the ASF dual-hosted git repository. kaxilnaik pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 277f33ce99b1f2a775820a22ce677bd45bb95e3c Author: YI FU <[email protected]> AuthorDate: Sat Jun 27 15:39:33 2020 +0200 show correct duration on graph view for running task (#8311) (#8675) * fix invalid end date (#8311) * Update airflow/www/static/js/task-instances.js Co-authored-by: Ash Berlin-Taylor <[email protected]> --- airflow/www_rbac/static/js/task-instances.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/airflow/www_rbac/static/js/task-instances.js b/airflow/www_rbac/static/js/task-instances.js index 8b25c4f..d650a2f 100644 --- a/airflow/www_rbac/static/js/task-instances.js +++ b/airflow/www_rbac/static/js/task-instances.js @@ -20,12 +20,18 @@ /* global window, dagTZ, moment, convertSecsToHumanReadable */ // We don't re-import moment again, otherwise webpack will include it twice in the bundle! -import { defaultFormat, formatDateTime } from './datetime-utils'; import { escapeHtml } from './base'; +import { defaultFormat, formatDateTime } from './datetime-utils'; function makeDateTimeHTML(start, end) { + // check task ended or not + if (end && end instanceof moment) { + return ( + `Started: ${start.format(defaultFormat)} <br> Ended: ${end.format(defaultFormat)} <br>` + ) + } return ( - `Started: ${start.format(defaultFormat)} <br> Ended: ${end.format(defaultFormat)} <br>` + `Started: ${start.format(defaultFormat)} <br> Ended: Not ended yet <br>` ) } @@ -47,13 +53,15 @@ function generateTooltipDateTimes(startDate, endDate, dagTZ) { // Generate User's Local Start and End Date startDate.tz(localTZ); tooltipHTML += `<br><strong>Local: ${startDate.format(tzFormat)}</strong><br>`; - tooltipHTML += makeDateTimeHTML(startDate, endDate.tz(localTZ)); + const localEndDate = endDate && endDate instanceof moment ? endDate.tz(localTZ) : endDate; + tooltipHTML += makeDateTimeHTML(startDate, localEndDate); // Generate DAG's Start and End Date if (dagTZ !== 'UTC' && dagTZ !== localTZ) { startDate.tz(dagTZ); tooltipHTML += `<br><strong>DAG's TZ: ${startDate.format(tzFormat)}</strong><br>`; - tooltipHTML += makeDateTimeHTML(startDate, endDate.tz(dagTZ)); + const dagTZEndDate = endDate && endDate instanceof moment ? endDate.tz(dagTZ) : endDate; + tooltipHTML += makeDateTimeHTML(startDate, dagTZEndDate); } return tooltipHTML; @@ -80,6 +88,12 @@ export default function tiTooltip(ti, {includeTryNumber = false} = {}) { } else { tt += `Started: ${escapeHtml(ti.start_date)}<br>`; } + // Calculate duration on the fly if task instance is still running + if(ti.state === "running") { + let start_date = ti.start_date instanceof moment ? ti.start_date : moment(ti.start_date); + ti.duration = moment().diff(start_date, 'second') + } + tt += `Duration: ${escapeHtml(convertSecsToHumanReadable(ti.duration))}<br>`; if (includeTryNumber) {
