Index: trunk/ippMonitor/czartool/czarpoll.pl
===================================================================
--- trunk/ippMonitor/czartool/czarpoll.pl	(revision 40878)
+++ trunk/ippMonitor/czartool/czarpoll.pl	(revision 40879)
@@ -128,4 +128,5 @@
 ###########################################################################
 sub updateLabels {
+    my ($dbupdate) = @_;
 
     # this used to have a concept of labels grouped by pantasks server, but we 
@@ -200,15 +201,17 @@
 
     # store them all in stdscience:
-    $server = "stdscience";
-    if (@allLabels) {
-	$czarDb->updateCurrentLabels($server, \@allLabels,'gpc1', \@priorities);
-    } else {
-	print "WARNING: No labels to update for gpc1 for '$server'\n";
-    }
-
-    if (@allLabels2) {
-	$czarDb->updateCurrentLabels($server, \@allLabels2,'gpc2', \@priorities2);
-    } else {
-	print "WARNING: No labels to update for gpc2 for '$server'\n";
+    if($dbupdate == 1) {
+        $server = "stdscience";
+        if (@allLabels) {
+	    $czarDb->updateCurrentLabels($server, \@allLabels,'gpc1', \@priorities);
+        } else {
+	    print "WARNING: No labels to update for gpc1 for '$server'\n";
+        }
+
+        if (@allLabels2) {
+	    $czarDb->updateCurrentLabels($server, \@allLabels2,'gpc2', \@priorities2);
+        } else {
+	    print "WARNING: No labels to update for gpc2 for '$server'\n";
+        }
     }
     return(\@allLabels,\@allLabels2);
@@ -244,4 +247,5 @@
     my ($period) = @_;
 
+    my $dbupdate;
     my $polldate;
     my $datenow;
@@ -271,4 +275,6 @@
     # main polling loop
     while (1) {
+        my $iterationStartTime = time();
+
         #get the time of last czarpoll update
         $polldate = $czarDb->getPollDate();
@@ -279,14 +285,14 @@
         $datenow=DateTime->now;
         $timediff = ($datenow->epoch) - ($date->epoch); 
-        if($timediff < 300.) { 
+        if($timediff > 120.) { 
+            print "There is no recent Czarpoll iteration\n";
+            print "*Updating database entries*\n";
+            $dbupdate = 1;
+        } else {
             print "There is a recent Czarpoll iteration already made ($timediff sec ago)\n";
-            print "* Going to sleep\n";
-            sleep($period);
-            print "* Waking up\n";
-
-            next;
-        }
-
-        my $iterationStartTime = time();
+            print "*Skipping database queries and entries*\n";
+            $dbupdate = 0;
+        }
+
 
         # sort out times
@@ -318,8 +324,10 @@
 
                 # now cleanup tables from yesterday and optimize
-                print "* Performing database cleanup\n";
-                $czarDb->cleanupDateRange($yesterday, $yesterday, $config->getCzarCleanupInterval());
-                print "* Optimizing the database\n";
-                $czarDb->optimize();
+                #TdB20190703: The ipp113 and ipp117 instances of czarpoll use the same stage DBs in czarDB. 
+                #Therefore, it makes no sense to run the cleanup+optimising twice
+                #print "* Performing database cleanup\n";
+                #$czarDb->cleanupDateRange($yesterday, $yesterday, $config->getCzarCleanupInterval());
+                #print "* Optimizing the database\n";
+                #$czarDb->optimize();
                 $lastDayDailyTasks = $yesterday;
             }
@@ -327,23 +335,25 @@
 
         # check nightly science status
-        print "* Checking nightly science status\n";
-        if (!$pantasks->getNightlyScienceStatus(\$nsStatus,'gpc1')) {$nsStatus = "Unknown";}
-        $czarDb->updateNightlyScience($nsStatus,'gpc1');
-        if (!$pantasks->getNightlyScienceStatus(\$nsStatus,'gpc2')) {$nsStatus = "Unknown";}
-        $czarDb->updateNightlyScience($nsStatus,'gpc2');
+        if($dbupdate == 1) {
+            print "* Checking nightly science status\n";
+            if (!$pantasks->getNightlyScienceStatus(\$nsStatus,'gpc1')) {$nsStatus = "Unknown";}
+            $czarDb->updateNightlyScience($nsStatus,'gpc1');
+            if (!$pantasks->getNightlyScienceStatus(\$nsStatus,'gpc2')) {$nsStatus = "Unknown";}
+            $czarDb->updateNightlyScience($nsStatus,'gpc2');
+        }
 
         # check nebulous
         print "* Checking Nebulous\n";
-        $nebulous->updateClusterSpaceInfo();
+        if($dbupdate == 1) {$nebulous->updateClusterSpaceInfo();}
         $plotter0->plotStorageTimeSeries($czarDb->subtractInterval($begin, "1 WEEK") , $end);
         $plotter0->plotDiskUsageHistogram();
         $plotter0->plotDiskUsageHistogramLarge();
-        updateServerStatus();
+        if($dbupdate == 1) {updateServerStatus();}
 
         # check pantasks dates
-        updateDates();
+        if($dbupdate == 1) {updateDates();}
 
         # check labels
-        my ($labels, $labels2) = updateLabels();
+        my ($labels, $labels2) = updateLabels($dbupdate);
         my @labels = @$labels;
         my @labels2 = @$labels2;
@@ -362,5 +372,5 @@
             my $size = @{$labels};
             if($size > 0) {
-                updateAllStages($thisServer, $newState, $labels,$labels2, $begin, $end);
+                if($dbupdate == 1) {updateAllStages($thisServer, $newState, $labels,$labels2, $begin, $end);}
                 if ($thisServer eq "stdscience") {
                     createPlots($thisServer, $plotter1, $labels, $begin, $end);
