You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/12/16 03:20:19 UTC

[GitHub] kaxil closed pull request #4304: [AIRFLOW-3500] Make task duration display user friendly

kaxil closed pull request #4304: [AIRFLOW-3500] Make task duration display user friendly
URL: https://github.com/apache/incubator-airflow/pull/4304
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/www/templates/airflow/graph.html b/airflow/www/templates/airflow/graph.html
index 33cdd9737b..1fede359a6 100644
--- a/airflow/www/templates/airflow/graph.html
+++ b/airflow/www/templates/airflow/graph.html
@@ -282,13 +282,24 @@
               tt += "Operator: " + task.task_type + "<br>";
               tt += "Started: " + ti.start_date + "<br>";
               tt += "Ended: " + ti.end_date + "<br>";
-              tt += "Duration: " + ti.duration + "<br>";
+              tt += "Duration: " + secondsToString(ti.duration) + "<br>";
               tt += "State: " + ti.state + "<br>";
               return tt;
             });
         });
     }
 
+    function secondsToString(seconds) {
+        var numdays = Math.floor((seconds % 31536000) / 86400); 
+        var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
+        var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
+        var numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60);
+        return (numdays > 0    ? numdays    + (numdays    === 1 ? " day "    : " days ")    : "") +
+               (numhours > 0   ? numhours   + (numhours   === 1 ? " hour "   : " hours ")   : "") +
+               (numminutes > 0 ? numminutes + (numminutes === 1 ? " minute " : " minutes ") : "") +
+               (numseconds > 0 ? numseconds + (numseconds === 1 ? " second"  : " seconds")  : "");
+    }
+
     function clearFocus(){
         d3.selectAll("g.node")
             .transition(duration)
diff --git a/airflow/www_rbac/static/js/datetime-utils.js b/airflow/www_rbac/static/js/datetime-utils.js
index 08e9469479..31a944f3a1 100644
--- a/airflow/www_rbac/static/js/datetime-utils.js
+++ b/airflow/www_rbac/static/js/datetime-utils.js
@@ -58,3 +58,14 @@ export const converAndFormatUTC = (datetime, tz) => {
   if (tz) dateTimeObj = dateTimeObj.tz(tz);
   return dateTimeObj.format(defaultFormatWithTZ)
 }
+
+export const secondsToString = (seconds) => {
+  let numdays    = Math.floor((seconds % 31536000) / 86400); 
+  let numhours   = Math.floor(((seconds % 31536000) % 86400) / 3600);
+  let numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
+  let numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60);
+  return (numdays > 0    ? numdays    + (numdays    === 1 ? " day "    : " days ")    : "") +
+         (numhours > 0   ? numhours   + (numhours   === 1 ? " hour "   : " hours ")   : "") +
+         (numminutes > 0 ? numminutes + (numminutes === 1 ? " minute " : " minutes ") : "") +
+         (numseconds > 0 ? numseconds + (numseconds === 1 ? " second"  : " seconds")  : "");
+}
\ No newline at end of file
diff --git a/airflow/www_rbac/static/js/graph.js b/airflow/www_rbac/static/js/graph.js
index 3ccc72cc6f..689623beab 100644
--- a/airflow/www_rbac/static/js/graph.js
+++ b/airflow/www_rbac/static/js/graph.js
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-import { generateTooltipDateTime, converAndFormatUTC } from './datetime-utils';
+import { generateTooltipDateTime, converAndFormatUTC, secondsToString } from './datetime-utils';
 
 // Assigning css classes based on state to nodes
 // Initiating the tooltips
@@ -38,7 +38,7 @@ function update_nodes_states(task_instances) {
           tt += "run_id: <nobr>" + ti.run_id + "</nobr><br>";
         }
         tt += "Operator: " + task.task_type + "<br>";
-        tt += "Duration: " + ti.duration + "<br>";
+        tt += "Duration: " + secondsToString(ti.duration) + "<br>";
         tt += "State: " + ti.state + "<br>";
         tt += generateTooltipDateTime(ti.start_date, ti.end_date, dagTZ); // dagTZ has been defined in dag.html
         return tt;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services