fix: working tasks after first tests
TS Lint / ESLint (push) Successful in 1m0s
Python Lint CI / ty (push) Successful in 1m6s
Python Lint CI / ruff (push) Successful in 1m7s
Python Lint CI / ruff-format-check (push) Successful in 1m12s
TS Lint / Oxlint (push) Failing after 4m55s
TS Lint / TypeScript (push) Successful in 5m15s

This commit is contained in:
2026-07-05 23:07:11 +02:00
parent 568f22e2d5
commit 56a41989f0
7 changed files with 50 additions and 64 deletions
+5 -1
View File
@@ -1,4 +1,5 @@
import tortoise
import typing
import tortoise.models
@@ -9,3 +10,6 @@ class AbstractModel(tortoise.models.Model):
class Meta:
abstract = True
def serialize(self) -> dict[str, typing.Any]:
return dict(self) # ty:ignore[no-matching-overload]
+24 -27
View File
@@ -1,50 +1,47 @@
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})/"
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 = tortoise.fields.CharField(max_length=32, db_index=True, null=False)
list_name = tortoise.fields.CharField(max_length=32, db_index=True, null=False)
name = tortoise.fields.TextField(null=False)
reset_cron = tortoise.fields.CharField(max_length=64, null=True)
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 = {}
try:
for field in [
"list",
"name",
"reset_cron",
"check_date",
"previous_check_date",
]:
getattr(cls, field).validate(data.get(field))
out_data[field] = data.get(field)
except tortoise.exceptions.ValidationError:
return None
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 = {}
try:
for field in [
"name",
"reset_cron",
"check_date",
"previous_check_date",
]:
if field in data:
getattr(cls, field).validate(data["field"])
out_data[field] = data["field"]
except tortoise.exceptions.ValidationError:
return None
for field in [
"name",
"reset_cron",
"check_date",
"previous_check_date",
]:
if field in data:
out_data[field] = data["field"]
return out_data