NathanJKW / Syncatron

0 stars 0 forks source link

Implement Scheduler #23

Closed NathanJKW closed 3 months ago

NathanJKW commented 3 months ago
import os
import time
import logging
import sched
from typing import List

def perform_git_pull(sc, interval: int):
    logging.info("Executing pull_repositories.")
    # Your actual logic for pulling repositories goes here
    logging.info("Ping for now.")
    sc.enter(interval, 1, perform_git_pull, (sc, interval))

def main(interval: int, access_token: str, directories: List[str]) -> None:
    """
    Main function that orchestrates the program.

    Args:
        interval (int): The interval in seconds between each execution.
        access_token (str): Personal access token for authentication.
        directories (List[str]): List of directory paths to perform git pull on.
    """
    run_frequency = os.getenv('RUN_FREQUENCY')
    project_folder = os.getenv('PROJECT_FOLDER')
    access_key = os.getenv('GIT_ACCESS_KEY')

    if not isinstance(run_frequency, int) or run_frequency <= 0:
        raise ValueError("Interval should be a positive integer.")

    scheduler = sched.scheduler(time.time, time.sleep)
    scheduler.enter(0, 1, perform_git_pull, (scheduler, interval))

    try:
        scheduler.run()  # This will run the schedule and execute the tasks at the specified interval
    except KeyboardInterrupt:
        logging.info("Program interrupted. Exiting gracefully.")