From 67043a69c5c36fdf10b1fc8748e7e10b86a496c8 Mon Sep 17 00:00:00 2001 From: hyokeun Date: Mon, 4 Dec 2017 16:16:10 +0900 Subject: [PATCH] Do not update OBS scailing log if there is no changes Change-Id: Ic4a25240fac4773fbb67e8e7d766d50dbb7dcfd4 --- job_obs_worker_auto_scailing.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/job_obs_worker_auto_scailing.py b/job_obs_worker_auto_scailing.py index 6b63daa..8fce2b0 100644 --- a/job_obs_worker_auto_scailing.py +++ b/job_obs_worker_auto_scailing.py @@ -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): -- 2.7.4