Skip to content

Commit 527798a

Browse files
authored
Merge pull request #298 from nix-community/failed-db
only initialze failedbuilddb once
2 parents 5b9a939 + 3fae0fd commit 527798a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

buildbot_nix/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,9 @@ def activate(self) -> Generator[Any, object, Any]:
14701470
yield super().activate()
14711471

14721472

1473+
DB = None
1474+
1475+
14731476
class NixConfigurator(ConfiguratorBase):
14741477
"""Janitor is a configurator which create a Janitor Builder with all needed Janitor steps"""
14751478

@@ -1530,9 +1533,11 @@ def configure(self, config: dict[str, Any]) -> None:
15301533
)
15311534
)
15321535

1533-
db = FailedBuildDB(Path("failed_builds.dbm"))
1534-
# Hacky but we have no other hooks just now to run code on shutdown.
1535-
atexit.register(lambda: db.close())
1536+
global DB # noqa: PLW0603
1537+
if DB is None:
1538+
DB = FailedBuildDB(Path("failed_builds.dbm"))
1539+
# Hacky but we have no other hooks just now to run code on shutdown.
1540+
atexit.register(lambda: DB.close() if DB is not None else None)
15361541

15371542
for project in projects:
15381543
config_for_project(
@@ -1545,7 +1550,7 @@ def configure(self, config: dict[str, Any]) -> None:
15451550
eval_lock,
15461551
[x.to_buildstep() for x in self.config.post_build_steps],
15471552
self.config.job_report_limit,
1548-
failed_builds_db=db,
1553+
failed_builds_db=DB,
15491554
outputs_path=self.config.outputs_path,
15501555
)
15511556

0 commit comments

Comments
 (0)