make the task handler timer configurable

This commit is contained in:
arabcoders 2025-06-18 17:23:42 +03:00
parent 888ab30bfc
commit f6c44245f6
3 changed files with 16 additions and 3 deletions

View file

@ -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 * * *` |

View file

@ -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",
)

View file

@ -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."