diff options
Diffstat (limited to 'buildbot_gentoo_ci/db/connector.py')
-rw-r--r-- | buildbot_gentoo_ci/db/connector.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/buildbot_gentoo_ci/db/connector.py b/buildbot_gentoo_ci/db/connector.py index 7665f84..0cc7884 100644 --- a/buildbot_gentoo_ci/db/connector.py +++ b/buildbot_gentoo_ci/db/connector.py @@ -15,7 +15,7 @@ # Copyright Buildbot Team Members # Origins: buildbot.db.connector.py # Modifyed by Gentoo Authors. -# Copyright 2021 Gentoo Authors +# Copyright 2023 Gentoo Authors import textwrap @@ -70,6 +70,10 @@ class DBConnector(service.ReconfigurableServiceMixin, self.setName('db') self.basedir = basedir + # not configured yet - we don't build an engine until the first + # reconfig + self.configured_url = None + # set up components self._engine = None # set up in reconfigService self.pool = None # set up in reconfigService @@ -88,12 +92,16 @@ class DBConnector(service.ReconfigurableServiceMixin, self.builds = builds.BuildsConnectorComponent(self) self.workers = workers.WorkersConnectorComponent(self) + self.cleanup_timer = internet.TimerService(self.CLEANUP_PERIOD, + self._doCleanup) + self.cleanup_timer.clock = self.master.reactor + yield self.cleanup_timer.setServiceParent(self) + @defer.inlineCallbacks def setup(self, config, check_version=True, verbose=True): - db_url = config.db['db_url'] + db_url = self.configured_url = config.db['db_url'] - log.msg("Setting up database with URL %r" - % util.stripUrlPassword(db_url)) + log.msg(f"Setting up database with URL {repr(util.stripUrlPassword(db_url))}") # set up the engine and pool self._engine = enginestrategy.create_engine(db_url, @@ -113,3 +121,22 @@ class DBConnector(service.ReconfigurableServiceMixin, for l in upgrade_message.format(basedir=self.basedir).split('\n'): log.msg(l) raise exceptions.DatabaseNotReadyError() + + def reconfigServiceWithBuildbotConfig(self, new_config): + # double-check -- the master ensures this in config checks + assert self.configured_url == new_config.db['db_url'] + + return super().reconfigServiceWithBuildbotConfig(new_config) + + def _doCleanup(self): + """ + Perform any periodic database cleanup tasks. + @returns: Deferred + """ + # pass on this if we're not configured yet + if not self.configured_url: + return None + + d = self.changes.pruneChanges(self.master.config.changeHorizon) + d.addErrback(log.err, 'while pruning changes') + return d |