From f6c44245f633b0937b27934f8f5970881a7c7a9e Mon Sep 17 00:00:00 2001 From: arabcoders Date: Wed, 18 Jun 2025 17:23:42 +0300 Subject: [PATCH] make the task handler timer configurable --- README.md | 1 + app/library/Tasks.py | 13 +++++++++++-- app/library/config.py | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cc944ec1..5fbb95c7 100644 --- a/README.md +++ b/README.md @@ -312,4 +312,5 @@ Certain configuration values can be set via environment variables, using the `-e | YTP_YTDLP_AUTO_UPDATE | Whether to enable the auto update for yt-dlp | `true` | | YTP_BASE_PATH | Set this if you are serving YTPTube from sub-folder | `/` | | YTP_PREVENT_LIVE_PREMIERE | Prevents the initial youtube premiere stream from being downloaded | `false` | +| YTP_TASKS_HANDLER_TIMER | The cron expression for the tasks handler timer. | `*15 */1 * * *` | diff --git a/app/library/Tasks.py b/app/library/Tasks.py index 862e41ff..698534b0 100644 --- a/app/library/Tasks.py +++ b/app/library/Tasks.py @@ -342,12 +342,21 @@ class Tasks(metaclass=Singleton): class HandleTask: _tasks: Tasks - def __init__(self, scheduler: Scheduler, tasks: Tasks) -> None: + def __init__(self, scheduler: Scheduler, tasks: Tasks, config: Config) -> None: self._tasks = tasks self._handlers: list[type] = self._discover() + timer = config.tasks_handler_timer + try: + from cronsim import CronSim + + CronSim(timer, datetime.now(UTC)) + except Exception as e: + timer = "15 */1 * * *" + LOG.error(f"Invalid timer format. '{e!s}'. Defaulting to '{timer}'.") + scheduler.add( - timer="15 */1 * * *", + timer=timer, func=self._dispatcher, id=f"{__class__.__name__}._dispatcher", ) diff --git a/app/library/config.py b/app/library/config.py index 5337a7eb..cc269215 100644 --- a/app/library/config.py +++ b/app/library/config.py @@ -143,6 +143,9 @@ class Config: secret_key: str "The secret key to use for the application." + tasks_handler_timer: str = "15 */1 * * *" + """The cron expression for the tasks timer.""" + console_enabled: bool = False "Enable direct access to yt-dlp console." @@ -182,7 +185,6 @@ class Config: "version", "__instance", "ytdl_options", - "tasks", "new_version_available", "started", "ytdlp_cli", @@ -239,6 +241,7 @@ class Config: "base_path", "is_native", "app_env", + "tasks_handler_timer", ) "The variables that are relevant to the frontend."