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 11, 2024
1 parent 11eeae2 commit 20620fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 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
2 changes: 2 additions & 0 deletions aioclock/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
MinuteT = Annotated[int, Interval(ge=0, le=59)]
HourT = Annotated[int, Interval(ge=0, le=24)]

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


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

0 comments on commit 20620fd

Please sign in to comment.