koji-gc: use history to query trashcan contents

as a side effect, we get the hub to apply our grace period for us
This commit is contained in:
Mike McLean 2022-12-02 17:16:49 -05:00 committed by Tomas Kopecek
parent 0034e9eb8d
commit 3c0fc0b4b1

View file

@ -664,11 +664,19 @@ def handle_delete(just_salvage=False):
"""
print("Getting list of builds in trash...")
trashcan_tag = options.trashcan_tag
trash = sorted([(b['nvr'], b) for b in session.listTagged(trashcan_tag)])
print("...got %i builds" % len(trash))
# XXX - it would be better if there were more appropriate server calls for this
grace_period = options.grace_period
import time
# using history makes for a smaller query that listTagged
history = session.queryHistory(tables=['tag_listing'],
tag=trashcan_tag,
active=True,
before=time.time()-grace_period)
# simulate needed binfo fields
binfos = history['tag_listing']
for binfo in binfos:
binfo['nvr'] = '%(name)s-%(version)s-%(release)s' % binfo
binfo['id'] = binfo['build_id']
trash = sorted([(b['nvr'], b) for b in binfos])
print("...got %i builds" % len(trash))
print("1st pass: blacklist")
continuing = []
@ -709,30 +717,7 @@ def handle_delete(just_salvage=False):
continue
continuing.append((nvr, binfo))
print("4th pass: history")
continuing, trash = [], continuing
for nvr, binfo in trash:
# determine how long this build has been in the trashcan
mcall.queryHistory(build=binfo['id'], tag=trashcan_tag)
for (nvr, binfo), [history] in zip(trash, mcall.call_all()):
current = [x for x in history['tag_listing'] if x['active']]
if not current:
# untagged just now?
print("Warning: history missing for %s" % nvr)
pprint.pprint(binfo)
pprint.pprint(history)
continue
assert len(current) == 1 # see db constraint
current = current[0]
age = time.time() - current['create_ts']
if age < grace_period:
if options.debug:
print("Skipping build %s, age=%i" % (nvr, age))
continue
continuing.append(binfo)
print("5th pass: deletion")
print("4th pass: deletion")
for binfo in continuing:
# go ahead and delete
if options.test: