diff options
Diffstat (limited to 'buildbot_gentoo_ci/steps/package.py')
-rw-r--r-- | buildbot_gentoo_ci/steps/package.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/buildbot_gentoo_ci/steps/package.py b/buildbot_gentoo_ci/steps/package.py index 13eafa2..847ba12 100644 --- a/buildbot_gentoo_ci/steps/package.py +++ b/buildbot_gentoo_ci/steps/package.py @@ -12,6 +12,7 @@ from twisted.python import log from buildbot.process.buildstep import BuildStep from buildbot.process.results import SUCCESS from buildbot.process.results import FAILURE +from buildbot.process.results import SKIPPED from buildbot.process import remotecommand from buildbot.plugins import steps @@ -282,3 +283,47 @@ class TriggerCheckForV(BuildStep): ) yield self.build.addStepsAfterCurrentStep(addStepUpdateVData) return SUCCESS + +class TriggerCleanPackageDb(BuildStep): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + name = 'TriggerCleanPackageDb' + description = 'Running' + descriptionSuffix = None + haltOnFailure = True + flunkOnFailure = True + + @defer.inlineCallbacks + def run(self): + self.gentooci = self.master.namedServices['services'].namedServices['gentooci'] + aftersteps_list = [] + # Check on deleted ebuild on package + deleted_ebuilds_data = yield self.gentooci.db.versions.getEbuildsByPackage(self.getProperty("package_data")['uuid'], deleted=True) + # check if older then X days + #FIXME: set days in config and move the check to db side + days = 30 + days_in_s = 86400 * days + needcleaning = 0 + now = int(self.master.reactor.seconds()) + for deleted_ebuild_data in deleted_ebuilds_data: + # check if older the days + if deleted_ebuild_data['deleted_at'] < (now - days_in_s): + needcleaning = needcleaning + 1 + print(f"{str(needcleaning)} ebuilds need cleaning in db") + if needcleaning > 0: + aftersteps_list.append( + steps.Trigger( + schedulerNames=['run_clean_db_request'], + waitForFinish=False, + updateSourceStamp=False, + set_properties={ + 'package_data' : self.getProperty("package_data"), + } + ) + ) + yield self.build.addStepsAfterCurrentStep(aftersteps_list) + self.descriptionDone = f"Need DB Cleaning: Yes" + return SUCCESS + self.descriptionDone = f"Need DB Cleaning: No" + return SKIPPED |