From 65b93837b099eb5f69b80bfa2de2b89fb07b92d3 Mon Sep 17 00:00:00 2001 From: Kamil Cukrowski Date: Mon, 15 Jul 2024 10:37:58 +0200 Subject: [PATCH] githubrunner: update --- .github/workflows/main.yml | 6 +++--- src/nomad_tools/entry_githubrunner.py | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6f3a99..2fb02b5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: - nomad: 1.6.8 python: 3.7 name: Test - runs-on: nomadtools tag=ubuntu-latest + runs-on: nomadtools steps: - name: checkout uses: actions/checkout@v4 @@ -47,7 +47,7 @@ jobs: test_ssl: name: Test ssl - runs-on: nomadtools tag=ubuntu-latest + runs-on: nomadtools steps: - name: checkout uses: actions/checkout@v4 @@ -69,7 +69,7 @@ jobs: - test_ssl if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') #if: github.ref == 'refs/heads/main' - runs-on: nomadtools tag=ubuntu-latest + runs-on: nomadtools environment: name: pypi url: https://pypi.org/p/nomad-tools diff --git a/src/nomad_tools/entry_githubrunner.py b/src/nomad_tools/entry_githubrunner.py index 1315141..d50e709 100644 --- a/src/nomad_tools/entry_githubrunner.py +++ b/src/nomad_tools/entry_githubrunner.py @@ -223,6 +223,7 @@ def get_runner_inactivity_timeout(self) -> Optional[datetime.timedelta]: namespace: default repos: - Kamilcuk/runnertest + - Kamilcuk/nomad-tools # - Kamilcuk loop: 1 """ @@ -582,7 +583,7 @@ def get_gh_repos() -> Set[GithubRepo]: return set(flatten(parallelmap(get_gh_repos_one_to_many, set(CONFIG.repos)))) -def get_gh_runs(repo: GithubRepo, run: dict) -> List[GithubJob]: +def get_gh_run_jobs(repo: GithubRepo, run: dict) -> List[GithubJob]: interesting = "queued in_progress".split() ret: List[GithubJob] = [] if run["status"] in interesting: @@ -596,16 +597,21 @@ def get_gh_runs(repo: GithubRepo, run: dict) -> List[GithubJob]: return ret -def get_gh_jobs(repo: GithubRepo) -> Iterable[GithubJob]: - runs = gh_get( - f"{CONFIG.github.url}/repos/{repo}/actions/runs", - "workflow_runs", +def get_gh_repo_jobs(repo: GithubRepo) -> Iterable[GithubJob]: + runs = flatten( + parallelmap( + lambda status: gh_get( + f"{CONFIG.github.url}/repos/{repo}/actions/runs?status={status}", + "workflow_runs", + ), + ["in_progress", "queued"], + ) ) - return flatten(parallelmap(lambda x: get_gh_runs(repo, x), runs)) + return flatten(parallelmap(lambda x: get_gh_run_jobs(repo, x), runs)) def get_gh_state(repos: Set[GithubRepo]) -> list[GithubJob]: - reqstate: list[GithubJob] = list(flatten(parallelmap(get_gh_jobs, repos))) + reqstate: list[GithubJob] = list(flatten(parallelmap(get_gh_repo_jobs, repos))) # desc: str = ", ".join(s.labelsstr() + " for " + s.job_url() for s in reqstate) # log.info(f"Found {len(reqstate)} required runners to run: {desc}") for idx, s in enumerate(reqstate): @@ -639,7 +645,7 @@ class NomadJob(nomadlib.Job, NomadJobCommon): @dataclass class GithubRunnerState: - inactive_since: Optional[datetime.datetime] = None + inactivu_since: Optional[datetime.datetime] = None class NomadRunner(nomadlib.JobsJob, NomadJobCommon): @@ -1001,7 +1007,7 @@ def scheduler(self) -> Todo: gj.labelsstr() for gj in self.githubjobs ) runninglabelsstrs: dict[str, int] = collections.Counter( - nr.labelsstr() for nr in self.nomadrunners + nr.labelsstr() for nr in self.nomadrunners if not nr.is_dead() ) alllabelsstrs: set[str] = set( itertools.chain(neededlabelsstrs.keys(), runninglabelsstrs.keys())