feat: clean git lock file for joj3

This commit is contained in:
张泊明518370910136 2024-11-03 01:45:41 -04:00
parent 78b97adec2
commit ebf7e04282
GPG Key ID: CA088E6D9284F870
2 changed files with 18 additions and 4 deletions

View File

@ -264,7 +264,9 @@ def joj3_scoreboard(
)
with FileLock(lock_file_path, timeout=settings.joj3_lock_file_timeout).acquire():
logger.info("file lock acquired")
repo_path = tea.pot.git.repo_clean_and_checkout(repo_name, "grading")
repo_path = tea.pot.git.repo_clean_and_checkout(
repo_name, "grading", clean_git_lock=True
)
repo: Repo = tea.pot.git.get_repo(repo_name)
if "grading" not in repo.remote().refs:
logger.error(
@ -344,7 +346,9 @@ def joj3_failed_table(
)
with FileLock(lock_file_path, timeout=settings.joj3_lock_file_timeout).acquire():
logger.info("file lock acquired")
repo_path = tea.pot.git.repo_clean_and_checkout(repo_name, "grading")
repo_path = tea.pot.git.repo_clean_and_checkout(
repo_name, "grading", clean_git_lock=True
)
repo: Repo = tea.pot.git.get_repo(repo_name)
if "grading" not in repo.remote().refs:
logger.error(
@ -555,7 +559,9 @@ def joj3_all(
retry_interval = 1
git_push_ok = False
while not git_push_ok:
repo_path = tea.pot.git.repo_clean_and_checkout(repo_name, "grading")
repo_path = tea.pot.git.repo_clean_and_checkout(
repo_name, "grading", clean_git_lock=True
)
repo: Repo = tea.pot.git.get_repo(repo_name)
if "grading" not in repo.remote().refs:
logger.error(

View File

@ -72,7 +72,11 @@ class Git:
return self.clone_repo(repo_name)
def repo_clean_and_checkout(
self, repo_name: str, checkout_dest: str, auto_retry: bool = True
self,
repo_name: str,
checkout_dest: str,
auto_retry: bool = True,
clean_git_lock: bool = False,
) -> str:
repo_dir = os.path.join(self.repos_dir, repo_name)
repo = self.get_repo(repo_name)
@ -81,6 +85,10 @@ class Git:
retry_interval = 2
while retry_interval and auto_retry:
try:
if clean_git_lock and os.path.exists(
os.path.join(repo_dir, ".git/index.lock")
):
os.remove(os.path.join(repo_dir, ".git/index.lock"))
repo.git.fetch("--tags", "--all", "-f")
repo.git.reset("--hard", "origin/master")
repo.git.clean("-d", "-f", "-x")