Skip to content

Commit

Permalink
feat: clean git lock file for joj3
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh committed Nov 3, 2024
1 parent 78b97ad commit ebf7e04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 9 additions & 3 deletions joint_teapot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 9 additions & 1 deletion joint_teapot/workers/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def get_repo(self, repo_name: str) -> Optional[Repo]:
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)
Expand All @@ -81,6 +85,10 @@ def repo_clean_and_checkout(
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")
Expand Down

0 comments on commit ebf7e04

Please sign in to comment.