Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop 4398906de -> 4487dd701


AIRAVATA-2212 Stop checking for status change once detected

Previous code had a bug where it would continue checking for a status
change after a status change was detected. This resulted in the page
trying to reload while it was loading, prevent the page from ever
actually loading in some cases.

Also added checking the job status for changes as well.


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/4487dd70
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/4487dd70
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/4487dd70

Branch: refs/heads/develop
Commit: 4487dd701c77d010b2f5cec31bf2cb6c6a9f1bbd
Parents: 4398906
Author: Marcus Christie <[email protected]>
Authored: Thu Nov 10 16:33:17 2016 -0500
Committer: Marcus Christie <[email protected]>
Committed: Thu Nov 10 16:33:17 2016 -0500

----------------------------------------------------------------------
 app/views/experiment/summary.blade.php | 55 ++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/4487dd70/app/views/experiment/summary.blade.php
----------------------------------------------------------------------
diff --git a/app/views/experiment/summary.blade.php 
b/app/views/experiment/summary.blade.php
index 6c44ede..653e15f 100755
--- a/app/views/experiment/summary.blade.php
+++ b/app/views/experiment/summary.blade.php
@@ -18,7 +18,34 @@
     @else
         var autoRefresh = false;
     @endif
-    setInterval(function () {
+
+    var currentJobStatuses = {};
+    @foreach( $expVal["jobDetails"] as $index => $jobDetail)
+    currentJobStatuses["{{$jobDetail->jobId}}"] = "{{ 
$jobDetail->jobStatuses[0]->jobStateName}}";
+    @endforeach
+
+    var isStatusChanged = function(experimentTimeOfStateChange, jobStatuses) {
+
+        if ($.trim($("#lastModifiedTime").val()) != 
experimentTimeOfStateChange) {
+            // console.log("Detected lastModifiedTime changed");
+            return true;
+        }
+        for (var jobId in jobStatuses) {
+            if (jobId in currentJobStatuses) {
+                if (currentJobStatuses[jobId] !== jobStatuses[jobId]){
+                    // console.log("Detected job status changed", jobId, 
currentJobStatuses[jobId], jobStatuses[jobId]);
+                    return true;
+                }
+            } else {
+                // console.log("Found a new job", jobId, jobStatuses[jobId]);
+                return true; // if job not in currentJobStatuses
+            }
+        }
+        return false;
+    }
+
+    // Check for a status change at most once every 3 seconds
+    var checkForStatusChange = function () {
         if (($.trim($(".exp-status").html()) != "COMPLETED" && 
$.trim($(".exp-status").html()) != "FAILED"
                 && $.trim($(".exp-status").html()) != "CANCELLED") && 
autoRefresh) {
             $.ajax({
@@ -27,14 +54,32 @@
                 data: {expId: "{{ Input::get('expId') }}", isAutoRefresh : 
autoRefresh },
                 success: function (data) {
                     data = $.parseJSON( data);
-                    //if ($.trim($("#expObj").val()) != $.trim(exp)) {
-                    if ($.trim($("#lastModifiedTime").val()) != $.trim( 
data.expVal["experimentTimeOfStateChange"])) {
+
+                    // Convert jobDetails to a map of jobStatuses
+                    var jobStatuses = {};
+                    var jobDetails = data["jobDetails"];
+                    for (var jobIndex in jobDetails){
+                        if (jobDetails.hasOwnProperty(jobIndex)) {
+                            var jobDetail = jobDetails[jobIndex];
+                            // Assuming only one job status per job
+                            jobStatuses[jobDetail["jobId"]] = 
jobDetail["jobStatuses"]["0"]["jobStateName"];
+                        }
+                    }
+
+                    if 
(isStatusChanged(data.expVal["experimentTimeOfStateChange"], jobStatuses)) {
                         $(".refresh-exp").click();
+                    } else {
+                        setTimeout(checkForStatusChange, 3000);
                     }
+                },
+                // In case of some spurious error, keep trying to check for 
status change
+                error: function() {
+                    setTimeout(checkForStatusChange, 3000);
                 }
             });
-       }
-    }, 3000);
+        }
+    };
+    setTimeout(checkForStatusChange, 3000);
 
     $('.btn-toggle').click(function() {
         if(autoRefresh){

Reply via email to