Skip to content

Commit

Permalink
Add GT=0 constraint to TaskMonitorEntity and descendants' update_inte…
Browse files Browse the repository at this point in the history
…rval property to ensure it cannot be set to 0
  • Loading branch information
user committed Dec 14, 2024
1 parent dd79b6a commit d39587e
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions avtdl/core/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple

import aiohttp
from pydantic import Field, FilePath, field_serializer, field_validator
from pydantic import Field, FilePath, PositiveFloat, field_serializer, field_validator

from avtdl.core.db import BaseDbConfig, RecordDB
from avtdl.core.interfaces import ActorConfig, Monitor, MonitorEntity, Record, RuntimeContext
Expand All @@ -17,7 +17,7 @@


class TaskMonitorEntity(MonitorEntity):
update_interval: float
update_interval: PositiveFloat
"""how often the monitored source should be checked for new content, in seconds"""


Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/fc2/fc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import aiohttp
import pydantic
from pydantic import Field
from pydantic import Field, PositiveFloat

from avtdl.core.config import Plugins
from avtdl.core.interfaces import ActorConfig, MAX_REPR_LEN, Record
Expand Down Expand Up @@ -65,7 +65,7 @@ class FC2MonitorConfig(ActorConfig):
class FC2MonitorEntity(HttpTaskMonitorEntity):
user_id: str
"""user id, numeric part at the end of livestream url"""
update_interval: int = 120
update_interval: PositiveFloat = 120
"""how often the monitored channel will be checked, in seconds"""
adjust_update_interval: bool = Field(exclude=True, default=True)
"""does nothing since fc2 does not use caching headers on the endpoint used to check live status"""
Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/nitter/nitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import aiohttp
import lxml.html
from dateutil import parser
from pydantic import ConfigDict
from pydantic import ConfigDict, PositiveFloat

from avtdl.core import utils
from avtdl.core.interfaces import Filter, FilterEntity, MAX_REPR_LEN, Record, RuntimeContext
Expand Down Expand Up @@ -123,7 +123,7 @@ class NitterMonitorConfig(PagedFeedMonitorConfig):

@Plugins.register('nitter', Plugins.kind.ACTOR_ENTITY)
class NitterMonitorEntity(PagedFeedMonitorEntity):
update_interval: float = 1800
update_interval: PositiveFloat = 1800
"""How often the monitored url will be checked, in seconds"""


Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/rplay/rplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import aiohttp
import dateutil.parser
from pydantic import Field, FilePath, model_validator
from pydantic import Field, FilePath, PositiveFloat, model_validator

from avtdl.core import utils
from avtdl.core.config import Plugins
Expand Down Expand Up @@ -87,7 +87,7 @@ class RplayMonitorConfig(BaseFeedMonitorConfig):
class RplayMonitorEntity(BaseFeedMonitorEntity):
creators: Optional[List[str]] = None
"""list of IDs of the users to monitor. Entity with no IDs will report on every user going live"""
update_interval: int = 300
update_interval: PositiveFloat = 300
"""how often the monitored channel will be checked, in seconds"""
selected_for_update: bool = Field(exclude=True, default=False)
"""internal variable, used to mark one entity that actually makes network request to update queues"""
Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/twitcast/twitcast_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional, Sequence

import aiohttp
from pydantic import Field
from pydantic import Field, PositiveFloat

from avtdl.core.config import Plugins
from avtdl.core.interfaces import ActorConfig, MAX_REPR_LEN, Record
Expand Down Expand Up @@ -49,7 +49,7 @@ def discord_embed(self) -> dict:
class TwitcastMonitorEntity(HttpTaskMonitorEntity):
user_id: str
"""user id that should be monitored"""
update_interval: float = 60
update_interval: PositiveFloat = 60
"""how often the user will be checked for being live, in seconds"""
adjust_update_interval: bool = Field(exclude=True, default=True)
"""does nothing since Twitcasting does not use caching headers on endpoint used to check live status"""
Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/twitch/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import aiohttp
from dateutil import parser as dateutil_parser
from pydantic import Field
from pydantic import Field, PositiveFloat

from avtdl.core.config import Plugins
from avtdl.core.interfaces import ActorConfig, MAX_REPR_LEN, Record
Expand Down Expand Up @@ -54,7 +54,7 @@ def discord_embed(self) -> dict:
class TwitchMonitorEntity(HttpTaskMonitorEntity):
username: str
"""Twitch username of a monitored channel"""
update_interval: int = 300
update_interval: PositiveFloat = 300
"""how often the user will be checked for being live, in seconds"""
most_recent_stream: Optional[str] = Field(exclude=True, default=None)
"""internal variable to persist state between updates. Used to keep last id to detect if the current livestream is the same as from the previous update"""
Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/twitter/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, List, Optional, Sequence, Tuple

import aiohttp
from pydantic import Field, FilePath
from pydantic import Field, FilePath, PositiveFloat

from avtdl.core.interfaces import Record
from avtdl.core.monitors import PagedFeedMonitor, PagedFeedMonitorConfig, PagedFeedMonitorEntity
Expand All @@ -28,7 +28,7 @@ class TwitterMonitorConfig(PagedFeedMonitorConfig):
class TwitterMonitorEntity(PagedFeedMonitorEntity):
cookies_file: FilePath
"""path to a text file containing cookies in Netscape format"""
update_interval: float = 1800
update_interval: PositiveFloat = 1800
"""how often the monitored url will be checked, in seconds"""
url: str = 'https://twitter.com'
"""Twitter domain name"""
Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/youtube/youtube_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union

import aiohttp
from pydantic import Field
from pydantic import Field, PositiveFloat

from avtdl.core import utils
from avtdl.core.interfaces import MAX_REPR_LEN, Record
Expand Down Expand Up @@ -125,7 +125,7 @@ class ChatPageContext(NextPageContext):
class YoutubeChatMonitorEntity(BaseFeedMonitorEntity):
url: str
"""url of a video frame with a chat"""
update_interval: float = Field(exclude=True, default=20)
update_interval: PositiveFloat = Field(exclude=True, default=20)
"""unavailable for configuration since update interval is determined dynamically based on chat speed"""
adjust_update_interval: bool = Field(exclude=True, default=False)
"""unavailable for configuration since update interval is determined dynamically based on chat speed"""
Expand Down
3 changes: 2 additions & 1 deletion avtdl/plugins/youtube/youtube_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union

import aiohttp
from pydantic import PositiveFloat

from avtdl.core import utils
from avtdl.core.interfaces import MAX_REPR_LEN, Record
Expand Down Expand Up @@ -151,7 +152,7 @@ class CommunityPostsMonitorConfig(PagedFeedMonitorConfig):
class CommunityPostsMonitorEntity(PagedFeedMonitorEntity):
url: str
"""url of the community page of the channel"""
update_interval: float = 1800
update_interval: PositiveFloat = 1800
"""how often the community page will be checked for new posts"""

@Plugins.register('community', Plugins.kind.ACTOR)
Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/youtube/youtube_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any, Dict, List, Optional, Sequence, Tuple

import aiohttp
from pydantic import Field, ValidationError
from pydantic import Field, PositiveFloat, ValidationError

from avtdl.core import utils
from avtdl.core.interfaces import Filter, FilterEntity, Record, RuntimeContext
Expand Down Expand Up @@ -111,7 +111,7 @@ class VideosMonitorConfig(PagedFeedMonitorConfig):

@Plugins.register('channel', Plugins.kind.ACTOR_ENTITY)
class VideosMonitorEntity(PagedFeedMonitorEntity):
update_interval: float = 1800
update_interval: PositiveFloat = 1800


class FeedPageContext(NextPageContext):
Expand Down
4 changes: 2 additions & 2 deletions avtdl/plugins/youtube/youtube_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import aiohttp
import feedparser
from pydantic import ConfigDict
from pydantic import ConfigDict, PositiveFloat

from avtdl.core import utils
from avtdl.core.config import Plugins
Expand Down Expand Up @@ -111,7 +111,7 @@ def discord_embed(self) -> dict:

@Plugins.register('rss', Plugins.kind.ACTOR_ENTITY)
class FeedMonitorEntity(GenericRSSMonitorEntity):
update_interval: float = 900
update_interval: PositiveFloat = 900
"""How often the feed should be updated, in seconds"""
track_reschedule: bool = False
"""keep track of scheduled time of upcoming streams, emit record again if it is changed to an earlier date"""
Expand Down

0 comments on commit d39587e

Please sign in to comment.