log regen ordering data
This commit is contained in:
parent
1a38131e63
commit
f2a6dc2f47
1 changed files with 24 additions and 2 deletions
26
util/kojira
26
util/kojira
|
|
@ -274,12 +274,16 @@ class RepoManager(object):
|
|||
data = session.listBuildroots(tagID=tag_id,
|
||||
queryOpts={'order': '-create_event_id', 'limit' : 100})
|
||||
#XXX magic number (limit)
|
||||
stats = {'data': data, 'ts': now}
|
||||
if data:
|
||||
tag_name = data[0]['tag_name']
|
||||
else:
|
||||
tag_name = "#%i" % tag_id
|
||||
stats = {'data': data, 'ts': now, 'tag_name': tag_name}
|
||||
recent = [x for x in data if now - x['create_ts'] < 3600 * 24]
|
||||
#XXX magic number
|
||||
stats ['n_recent'] = len(recent)
|
||||
self.tag_use_stats[tag_id] = stats
|
||||
self.logger.debug("tag %s recent use count: %i" % (tag_id, len(recent)))
|
||||
self.logger.debug("tag %s recent use count: %i" % (tag_name, len(recent)))
|
||||
return stats
|
||||
|
||||
def adjustRegenOrder(self, data):
|
||||
|
|
@ -296,9 +300,13 @@ class RepoManager(object):
|
|||
"""
|
||||
if not data:
|
||||
return []
|
||||
self.logger.info("Got %i tags for regeneration", len(data))
|
||||
if len(data) == 1:
|
||||
return data[:]
|
||||
data = [(ts, tag_id, self.tagUseStats(tag_id)) for ts, tag_id in data]
|
||||
max_n = max([s['n_recent'] for ts,tag,s in data])
|
||||
if max_n == 0:
|
||||
self.logger.info("No tags had recent use")
|
||||
ret = [(ts,tag) for ts,tag,s in data]
|
||||
ret.sort()
|
||||
return ret
|
||||
|
|
@ -306,14 +314,28 @@ class RepoManager(object):
|
|||
# adjustment could have the opposite of the desired effect
|
||||
now = time.time()
|
||||
ret = []
|
||||
names = {}
|
||||
for ts, tag_id, stats in data:
|
||||
names[tag_id] = stats['tag_name']
|
||||
#normalize use count
|
||||
adj = stats ['n_recent'] * 9.0 / max_n + 1 # 1.0 to 10.0
|
||||
sortvalue = (now-ts)*adj
|
||||
ret.append(((now-ts)*adj, tag_id))
|
||||
self.logger.debug("order adjustment: tag %s, ts %s, recent use %s, factor %s, new sort value %s",
|
||||
stats['tag_name'], ts, stats ['n_recent'], adj, sortvalue)
|
||||
#so a day old unused repo gets about the regen same priority as a
|
||||
#2.4-hour-old, very popular repo
|
||||
ret.sort()
|
||||
ret.reverse()
|
||||
if self.logger.isEnabledFor(logging.INFO):
|
||||
#show some stats
|
||||
by_ts = [(ts,names[tag]) for ts,tag,s in data]
|
||||
by_ts.sort()
|
||||
self.logger.info("Newest repo: %s (%.2fhrs)", by_ts[-1][1], (now - by_ts[-1][0])/3600.)
|
||||
self.logger.info("Oldest repo: %s (%.2fhrs)", by_ts[0][1], (now - by_ts[0][0])/3600.)
|
||||
self.logger.info("Best score: %s (%.1f)", names[ret[0][1]], ret[0][0])
|
||||
self.logger.info("Worst score: %s (%.1f)", names[ret[-1][1]], ret[-1][0])
|
||||
self.logger.info("Order: %s", [names[x[1]] for x in ret])
|
||||
return ret
|
||||
|
||||
def updateRepos(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue