mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 13:18:18 +00:00
Fallback to schedule automation in UTC timezone if unset
- Handle null automation ids in calls to get_automation function
This commit is contained in:
@@ -1794,7 +1794,7 @@ class AutomationAdapters:
|
||||
def get_automation(user: KhojUser, automation_id: str) -> Job:
|
||||
# Perform validation checks
|
||||
# Check if user is allowed to delete this automation id
|
||||
if not automation_id.startswith(f"automation_{user.uuid}_"):
|
||||
if not is_none_or_empty(automation_id) or automation_id.startswith(f"automation_{user.uuid}_"):
|
||||
raise ValueError("Invalid automation id")
|
||||
# Check if automation with this id exist
|
||||
automation: Job = state.scheduler.get_job(job_id=automation_id)
|
||||
|
||||
@@ -1977,7 +1977,13 @@ def schedule_automation(
|
||||
# Run automation at some random minute (to distribute request load) instead of running every X minutes
|
||||
crontime = " ".join([str(math.floor(random() * 60))] + crontime.split(" ")[1:])
|
||||
|
||||
user_timezone = pytz.timezone(timezone)
|
||||
# Convert timezone string to timezone object
|
||||
try:
|
||||
user_timezone = pytz.timezone(timezone)
|
||||
except pytz.UnknownTimeZoneError:
|
||||
logger.error(f"Invalid timezone: {timezone}. Fallback to use UTC to schedule automation.")
|
||||
user_timezone = pytz.utc
|
||||
|
||||
trigger = CronTrigger.from_crontab(crontime, user_timezone)
|
||||
trigger.jitter = 60
|
||||
# Generate id and metadata used by task scheduler and process locks for the task runs
|
||||
|
||||
Reference in New Issue
Block a user