File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,5 +9,6 @@ class VersionHandler(BaseHandler):
99 name = "version"
1010
1111 async def get (self , * args , ** kwargs ):
12- version = await asyncio .to_thread (get_version )
12+ loop = asyncio .get_running_loop ()
13+ version = await loop .run_in_executor (None , get_version )
1314 self .write ({"version" : version })
Original file line number Diff line number Diff line change 11import logging
22import os
33import pathlib
4- from collections . abc import Iterable
5- from functools import cache
4+ from functools import lru_cache
5+ from typing import Iterable , Optional
66
77from git import InvalidGitRepositoryError , NoSuchPathError , Repo
88
1414CONTAINER_VERSION_FILE = pathlib .Path ("/home/nodenorm/configuration" ) / VERSION_FILE_NAME
1515
1616
17- def read_version_file (version_file_paths : Iterable [pathlib .Path ] | None = None ) -> str | None :
17+ def read_version_file (version_file_paths : Optional [ Iterable [pathlib .Path ]] = None ) -> Optional [ str ] :
1818 """Read the build-time version file when the app is running from a packaged image."""
1919 candidate_paths = []
2020 configured_path = os .getenv (VERSION_FILE_ENV_VAR )
@@ -38,8 +38,8 @@ def read_version_file(version_file_paths: Iterable[pathlib.Path] | None = None)
3838 return None
3939
4040
41- @cache
42- def get_github_commit_hash (source_path : pathlib .Path | None = None ) -> str :
41+ @lru_cache ( maxsize = None )
42+ def get_github_commit_hash (source_path : Optional [ pathlib .Path ] = None ) -> str :
4343 """Retrieve the current GitHub commit hash using gitpython."""
4444 try :
4545 repo_path = source_path or pathlib .Path (__file__ ).resolve ()
@@ -54,6 +54,6 @@ def get_github_commit_hash(source_path: pathlib.Path | None = None) -> str:
5454 return UNKNOWN_VERSION
5555
5656
57- @cache
57+ @lru_cache ( maxsize = None )
5858def get_version () -> str :
5959 return read_version_file () or get_github_commit_hash ()
You can’t perform that action at this time.
0 commit comments