diff --git a/app/library/HttpAPI.py b/app/library/HttpAPI.py index f922e84a..b97c8dd1 100644 --- a/app/library/HttpAPI.py +++ b/app/library/HttpAPI.py @@ -1007,9 +1007,6 @@ class HttpAPI(Common): if not item.get("id", None) or not validate_uuid(item.get("id"), version=4): item["id"] = str(uuid.uuid4()) - if not item.get("timer", None) or str(item.get("timer")).strip() == "": - item["timer"] = f"{random.randint(1,59)} */1 * * *" # noqa: S311 - if not item.get("template", None): item["template"] = "" diff --git a/app/library/Tasks.py b/app/library/Tasks.py index ed3a448e..e529a54f 100644 --- a/app/library/Tasks.py +++ b/app/library/Tasks.py @@ -108,7 +108,7 @@ class Tasks(metaclass=Singleton): self.load() self._notify.subscribe( Events.TASKS_ADD, - lambda data, _, **kwargs: self.add(**data.data), # noqa: ARG005 + lambda data, _, **kwargs: self.save(**data.data), # noqa: ARG005 f"{__class__.__name__}.add", ) @@ -145,6 +145,7 @@ class Tasks(metaclass=Singleton): for i, task in enumerate(tasks): try: task, task_status = clean_item(task, keys=("cookies", "config")) + self.validate(task) task = Task(**task) if task_status: need_save = True @@ -152,9 +153,13 @@ class Tasks(metaclass=Singleton): LOG.error(f"Failed to parse task at list position '{i}'. '{e!s}'.") continue + self._tasks.append(task) + + if not task.timer: + continue + try: self._scheduler.add(timer=task.timer, func=self._runner, args=(task,), id=task.id) - self._tasks.append(task) try: from cronsim import CronSim @@ -221,14 +226,19 @@ class Tasks(metaclass=Singleton): msg = "No name found." raise ValueError(msg) - if not task.get("timer"): - msg = "No timer found." - raise ValueError(msg) - if not task.get("url"): msg = "No URL found." raise ValueError(msg) + if task.get("timer"): + try: + from cronsim import CronSim + + CronSim(task.get("timer"), datetime.now(UTC)) + except Exception as e: + msg = f"Invalid timer format. '{e!s}'." + raise ValueError(msg) from e + if task.get("cli"): try: from .Utils import arg_converter diff --git a/ui/components/TaskForm.vue b/ui/components/TaskForm.vue index 7f93eac1..fcf0b1ef 100644 --- a/ui/components/TaskForm.vue +++ b/ui/components/TaskForm.vue @@ -126,16 +126,15 @@ CRON expression timer.
- +
- The CRON timer expression to use for this task. If not set, the task will run once an hour in a - random - minute. For more information on CRON expressions, see crontab.guru. + The CRON timer expression to use for this task. If not set, the task will be disabled. For more + information on CRON expressions, see + crontab.guru. diff --git a/ui/pages/tasks.vue b/ui/pages/tasks.vue index 849f3c0f..f56c486f 100644 --- a/ui/pages/tasks.vue +++ b/ui/pages/tasks.vue @@ -67,7 +67,8 @@ div.is-centered {

- {{ tryParse(item.timer) }} - {{ item.timer }} + {{ tryParse(item.timer) }} - {{ item.timer }} + No timer is set

@@ -102,7 +103,7 @@ div.is-centered {