Skip to content

Commit

Permalink
Add wait time between fetches/clones
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofachada committed Feb 24, 2024
1 parent dde69f1 commit bb38349
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 9 additions & 0 deletions egrader/cli_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def main():
default=OPT_E_STOP,
)

parser_fetch.add_argument(
"-w",
"--wait",
help="time in seconds to wait between clones/fetches (default: 0)",
metavar="SECS",
type=float,
default=0,
)

parser_fetch.add_argument(
"urls_file",
metavar="URLS",
Expand Down
22 changes: 20 additions & 2 deletions egrader/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
from argparse import Namespace
from pathlib import Path
from time import sleep
from typing import List, Sequence

from .cli_lib import OPT_E_LONG, OPT_E_OVWR, OPT_E_SHORT, OPT_E_STOP, check_empty_args
Expand All @@ -28,6 +29,9 @@ def fetch(assess_fp: Path, args: Namespace, extra_args: Sequence[str]) -> None:
urls_fp: Path = Path(args.urls_file)
rules_fp: Path = Path(args.rules_file)

# Time to wait between fetches
wait_time: float = args.wait

# Check if Git URLs file exists, and if not, quit
check_required_fp_exists(urls_fp)

Expand Down Expand Up @@ -74,7 +78,7 @@ def fetch(assess_fp: Path, args: Namespace, extra_args: Sequence[str]) -> None:

# Clone or update student repositories
n_valid_urls = fetch_repos(
assess_fp, students_git, [rule["repo"] for rule in repo_rules]
assess_fp, students_git, [rule["repo"] for rule in repo_rules], wait_time
)

# Determine number of repositories
Expand All @@ -94,19 +98,30 @@ def fetch(assess_fp: Path, args: Namespace, extra_args: Sequence[str]) -> None:


def fetch_repos(
assess_fp: Path, students_git: Sequence[StudentGit], repos: Sequence[str]
assess_fp: Path,
students_git: Sequence[StudentGit],
repos: Sequence[str],
wait_time: float,
) -> int:
"""Clone or update student repositories."""
# Number of valid Git URLs
n_valid_urls = 0

# Already fetched/cloned anything?
any_fetch = False

# Loop through students
for student_git in students_git:
if student_git.valid_url:
n_valid_urls += 1

# Loop through mandated repos
for repo_name in repos:
# If a fetch/clone was already done, then wait the number of seconds
# specified by the user
if any_fetch:
sleep(wait_time)

# Determine repo URL and local path
repo_url: str = student_git.repo_url(repo_name)
repo_fp: Path = get_student_repo_fp(
Expand Down Expand Up @@ -134,6 +149,9 @@ def fetch_repos(
# Otherwise add repo location to student object
student_git.add_repo(repo_name, str(repo_fp))

# Indicate that at least one fetch/clone has been made
any_fetch = True

return n_valid_urls


Expand Down

0 comments on commit bb38349

Please sign in to comment.