aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Granberg <zorry@gentoo.org>2023-05-28 11:48:40 +0200
committerMagnus Granberg <zorry@gentoo.org>2023-05-28 11:48:40 +0200
commit2dfba1de696c99c0c03a8c1c6abd878b60f3c7fc (patch)
treee531ec7356041f0ff80ea31db12e9dd86f1633e8 /buildbot_gentoo_ci/db/connector.py
parentSet build_wait_timeout to 600 for log worker (diff)
downloadtinderbox-cluster-2dfba1de696c99c0c03a8c1c6abd878b60f3c7fc.tar.gz
tinderbox-cluster-2dfba1de696c99c0c03a8c1c6abd878b60f3c7fc.tar.bz2
tinderbox-cluster-2dfba1de696c99c0c03a8c1c6abd878b60f3c7fc.zip
Update db python code to bb3.8
Signed-off-by: Magnus Granberg <zorry@gentoo.org>
Diffstat (limited to 'buildbot_gentoo_ci/db/connector.py')
-rw-r--r--buildbot_gentoo_ci/db/connector.py35
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