Docker Build / build (push) Has been cancelled
Python Lint CI / ruff (push) Has been cancelled
Python Lint CI / ruff-format-check (push) Has been cancelled
Python Lint CI / ty (push) Has been cancelled
TS Lint / ESLint (push) Has been cancelled
TS Lint / Oxlint (push) Has been cancelled
TS Lint / TypeScript (push) Has been cancelled
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import typing
|
|
|
|
import tortoise
|
|
import tortoise.validators
|
|
|
|
from app.models.base import AbstractModel
|
|
|
|
# https://stackoverflow.com/a/57639657
|
|
CRONTAB_REGEX = r"^(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})$"
|
|
|
|
|
|
class Task(AbstractModel):
|
|
list_name = tortoise.fields.CharField(max_length=128, db_index=True, null=False)
|
|
name = tortoise.fields.TextField(null=False)
|
|
reset_cron = tortoise.fields.CharField(
|
|
max_length=64,
|
|
null=True,
|
|
validators=[tortoise.validators.RegexValidator(CRONTAB_REGEX, 0)],
|
|
)
|
|
check_date = tortoise.fields.DatetimeField(null=True)
|
|
previous_check_date = tortoise.fields.DatetimeField(null=True)
|
|
|
|
@classmethod
|
|
def validate_create(cls, data: dict[str, typing.Any]) -> dict | None:
|
|
out_data = {}
|
|
for field in [
|
|
"list_name",
|
|
"name",
|
|
"reset_cron",
|
|
"check_date",
|
|
"previous_check_date",
|
|
]:
|
|
out_data[field] = data.get(field)
|
|
return out_data
|
|
|
|
@classmethod
|
|
def validate_update(cls, data: dict[str, typing.Any]) -> dict | None:
|
|
out_data = {}
|
|
for field in [
|
|
"name",
|
|
"reset_cron",
|
|
"check_date",
|
|
"previous_check_date",
|
|
]:
|
|
if field in data:
|
|
out_data[field] = data[field]
|
|
return out_data
|