handle task times in the past
@@ -2,6 +2,9 @@ from loguru import logger
from tacticalrmm.celery import app
from django.conf import settings
from datetime import datetime as dt
+from datetime import timedelta
+import pytz
+from django.utils import timezone as djangotime
from .models import AutomatedTask
from logs.models import PendingAction
@@ -46,6 +49,14 @@ def create_win_task_schedule(pk, pending_action=False):
elif task.task_type == "runonce":
+ # check if scheduled time is in the past
+ agent_tz = pytz.timezone(task.agent.timezone)
+ task_time_utc = task.run_time_date.replace(tzinfo=agent_tz).astimezone(pytz.utc)
+ now = djangotime.now()
+ if task_time_utc < now:
+ task.run_time_date = now.astimezone(agent_tz) + timedelta(minutes=5)
+ task.save()
+
r = task.agent.salt_api_cmd(
timeout=20,
func="task.create_task",
