only refresh github projects in timer and sort them

This way errors are more visible to users on the first running.

Co-authored-by: zimbatm <zimbatm@zimbatm.com>
This commit is contained in:
Jörg Thalheim 2024-01-08 08:10:03 +01:00 committed by mergify[bot]
parent f22c113d1e
commit c9e850ff32
2 changed files with 20 additions and 5 deletions

View file

@ -755,6 +755,18 @@ def setup_authz(projects: list[GithubProject], admins: list[str]) -> util.Authz:
)
class PeriodicWithStartup(schedulers.Periodic):
def __init__(self, *args: Any, run_on_startup: bool = False, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.run_on_startup = run_on_startup
@defer.inlineCallbacks
def activate(self) -> Generator[Any, object, Any]:
if self.run_on_startup:
yield self.setState("last_build", None)
yield super().activate()
class NixConfigurator(ConfiguratorBase):
"""Janitor is a configurator which create a Janitor Builder with all needed Janitor steps"""
@ -841,11 +853,12 @@ class NixConfigurator(ConfiguratorBase):
builderNames=["reload-github-projects"],
buttonName="Update projects",
),
# project list twice a day
schedulers.Periodic(
# project list twice a day and on startup
PeriodicWithStartup(
name="reload-github-projects-bidaily",
builderNames=["reload-github-projects"],
periodicBuildTimer=12 * 60 * 60,
run_on_startup=not self.github.project_cache_file.exists(),
),
],
)

View file

@ -186,7 +186,9 @@ def refresh_projects(github_token: str, repo_cache_file: Path) -> None:
def load_projects(github_token: str, repo_cache_file: Path) -> list[GithubProject]:
if not repo_cache_file.exists():
log.msg("fetching github repositories")
refresh_projects(github_token, repo_cache_file)
repos: list[dict[str, Any]] = json.loads(repo_cache_file.read_text())
return []
repos: list[dict[str, Any]] = sorted(
json.loads(repo_cache_file.read_text()), key=lambda x: x["full_name"]
)
return [GithubProject(repo) for repo in repos]