feat: file lock on git operation

This commit is contained in:
张泊明518370910136 2024-10-17 22:51:35 -04:00
parent afb5d82421
commit 940112e696
GPG Key ID: CA088E6D9284F870
3 changed files with 80 additions and 64 deletions

View File

@ -3,6 +3,7 @@ from datetime import datetime
from pathlib import Path
from typing import List
from filelock import FileLock
from git import Repo
from typer import Argument, Option, Typer, echo
@ -249,6 +250,10 @@ def joj3_scoreboard(
logger.info(f"debug log to file: {settings.log_file_path}")
if joj3.check_skipped(score_file_path, "skip-scoreboard"):
return
lock = FileLock(
settings.joj3_lock_file_path, timeout=settings.joj3_lock_file_timeout
)
with lock.acquire():
repo_path = tea.pot.git.repo_clean_and_checkout(repo_name, "grading")
repo: Repo = tea.pot.git.get_repo(repo_name)
if "grading" not in repo.remote().refs:
@ -276,7 +281,9 @@ def joj3_scoreboard(
+ f"{settings.gitea_org_name}/{submitter_repo_name}@{commit_hash}\n\n"
+ f"gitea actions link: {actions_link}"
)
tea.pot.git.add_commit_and_push(repo_name, [scoreboard_file_name], commit_message)
tea.pot.git.add_commit_and_push(
repo_name, [scoreboard_file_name], commit_message
)
@app.command(
@ -318,6 +325,10 @@ def joj3_failed_table(
logger.info(f"debug log to file: {settings.log_file_path}")
if joj3.check_skipped(score_file_path, "skip-failed-table"):
return
lock = FileLock(
settings.joj3_lock_file_path, timeout=settings.joj3_lock_file_timeout
)
with lock.acquire():
repo_path = tea.pot.git.repo_clean_and_checkout(repo_name, "grading")
repo: Repo = tea.pot.git.get_repo(repo_name)
if "grading" not in repo.remote().refs:

View File

@ -35,9 +35,13 @@ class Settings(BaseSettings):
"charlem",
]
# sid
# joj
joj_sid: str = ""
# joj3
joj3_lock_file_path: str = ".git/teapot.lock"
joj3_lock_file_timeout: int = 30
# log file
log_file_path: str = "joint-teapot.log"
stderr_log_level: str = "INFO"

View File

@ -1,5 +1,6 @@
canvasapi>=2.2.0
colorama>=0.4.6
filelock>=3.14.0
focs_gitea>=1.22.0
GitPython>=3.1.18
joj-submitter>=0.0.8