Do not update OBS scailing log if there is no changes 47/162547/3
authorhyokeun <hyokeun.jeon@samsung.com>
Mon, 4 Dec 2017 07:16:10 +0000 (16:16 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Wed, 6 Dec 2017 00:00:47 +0000 (09:00 +0900)
Change-Id: Ic4a25240fac4773fbb67e8e7d766d50dbb7dcfd4

job_obs_worker_auto_scailing.py

index 6b63daa..8fce2b0 100644 (file)
@@ -25,7 +25,7 @@ import sys
 import base64
 from datetime import datetime
 import requests
-from common.utils import sync
+from common.utils import sync, unicode_to_str
 from common.buildtrigger import trigger_next
 import xml.etree.ElementTree as ElementTree
 
@@ -87,18 +87,26 @@ def get_worker_status():
     print '\n'
     sys.stdout.flush()
 
-    if ret_data['building_normal'] > 0 or ret_data['building_power'] > 0 \
-        or ret_data['waiting'] > 0:
+    #if ret_data['building_normal'] > 0 or ret_data['building_power'] > 0 \
+    #    or ret_data['waiting'] > 0:
+    if True:
         sync_src = os.path.join(os.getenv('JENKINS_HOME'), '.obs_worker_trend', 'obs_worker_history.log')
         sync_dest = os.path.join(os.getenv('IMG_SYNC_DEST_BASE'), 'snapshots', \
                                  '.dashboard', 'obs_worker_trend')
-        with open(sync_src, 'a') as wh:
-            wh.write('%s,%s,%s,%s,%s,%s,%s\n' \
+        curr_item = '%s,%s,%s,%s,%s,%s,%s\n' \
                      % (curr_time,
                         ret_data['idle_normal'], ret_data['idle_power'],
                         ret_data['building_normal'], ret_data['building_power'],
-                        ret_data['waiting'], ret_data['blocked']))
-        print sync(os.path.dirname(sync_src), sync_dest)
+                        ret_data['waiting'], ret_data['blocked'])
+        last_item = ''
+        with open(sync_src, 'rb') as rh:
+            rh.seek(-1024, os.SEEK_END)
+            last_item = rh.readlines()[-1].decode()
+        # Do not log if the last is the same as current
+        if unicode_to_str(curr_item).split(',')[1:-1] != unicode_to_str(last_item).split(',')[1:-1]:
+            with open(sync_src, 'a') as wh:
+                wh.write(curr_item)
+            print sync(os.path.dirname(sync_src), sync_dest)
     return ret_data
 
 def request_workers(num_executors, worker_type=OBS_NORMAL_WORKER):