Skip to content

Commit

Permalink
accept only positive numbers on Every() trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAref committed Apr 12, 2024
1 parent 11eeae2 commit a40260f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions aioclock/triggers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio
import zoneinfo
from abc import ABC, abstractmethod
from copy import deepcopy
from datetime import datetime, timedelta
from typing import Literal, Union

import zoneinfo
from pydantic import BaseModel, model_validator

from aioclock.types import EveryT, HourT, MinuteT, SecondT, Triggers
from aioclock.types import EveryT, HourT, MinuteT, PositiveNumber, SecondT, Triggers


class BaseTrigger(BaseModel, ABC):
Expand Down Expand Up @@ -69,11 +69,11 @@ def should_trigger(self) -> bool:
class Every(BaseTrigger):
type_: Literal[Triggers.EVERY] = Triggers.EVERY

seconds: Union[int, float, None] = None
minutes: Union[int, float, None] = None
hours: Union[int, float, None] = None
days: Union[int, float, None] = None
weeks: Union[int, float, None] = None
seconds: Union[PositiveNumber, None] = None
minutes: Union[PositiveNumber, None] = None
hours: Union[PositiveNumber, None] = None
days: Union[PositiveNumber, None] = None
weeks: Union[PositiveNumber, None] = None

@model_validator(mode="after")
def validate_time_units(self):
Expand Down
4 changes: 3 additions & 1 deletion aioclock/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import auto
from typing import Annotated, Literal
from typing import Annotated, Literal, Union

from annotated_types import Interval

Expand All @@ -20,6 +20,8 @@
MinuteT = Annotated[int, Interval(ge=0, le=59)]
HourT = Annotated[int, Interval(ge=0, le=24)]

PositiveNumber = Annotated[Union[int, float], Interval(ge=0)]


class Triggers(StrEnum):
# TODO: support cron job trigger
Expand Down

0 comments on commit a40260f

Please sign in to comment.