mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
add cron-based schedule trigger
This commit is contained in:
parent
f08b316441
commit
3b1d7c4389
4 changed files with 105 additions and 2 deletions
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||
|
||||
from .cron import InvalidCronError, validate_cron
|
||||
|
||||
|
||||
class ScheduleTriggerParams(BaseModel):
|
||||
|
|
@ -10,3 +12,11 @@ class ScheduleTriggerParams(BaseModel):
|
|||
|
||||
cron: str = Field(..., description="Five-field cron expression.", examples=["0 9 * * 1-5"])
|
||||
timezone: str = Field(..., description="IANA timezone.", examples=["Africa/Kigali"])
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _validate(self) -> ScheduleTriggerParams:
|
||||
try:
|
||||
validate_cron(self.cron, self.timezone)
|
||||
except InvalidCronError as exc:
|
||||
raise ValueError(str(exc)) from exc
|
||||
return self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue