fix: 피드 캐시를 다음 초단기예보가 나오는 시각(:45)에 끝내 비 반영 각 점수가 늦게 보이지 않게
This commit is contained in:
1 parent
8a677a766d
commit
055eec69ef
2 files changed
+15
-3
No files matched your search
@@ -13,7 +13,7 @@ from common.database.db_session_manager import DB_SESSION_MNG
|
|||||||
from common.database.model.models import Article, OpenMeteoHourly, Post, Region, WeatherHourly
|
from common.database.model.models import Article, OpenMeteoHourly, Post, Region, WeatherHourly
|
||||||
from common.enums import AirGrade, ArticleCategory, ErrorType, PostType, RainType, RefType, Sky, SkyGrade, SkySituation, SkyType, WarningType
|
from common.enums import AirGrade, ArticleCategory, ErrorType, PostType, RainType, RefType, Sky, SkyGrade, SkySituation, SkyType, WarningType
|
||||||
from common.logger import LOG
|
from common.logger import LOG
|
||||||
from common.utils.kma_time import KST, kst_midnight, next_vilage_available, now_kst
|
from common.utils.kma_time import KST, ULTRA_DELAY, kst_midnight, latest_ultra_base, next_vilage_available, now_kst
|
||||||
from common.utils.text import compass, day_range, hour_label, short_day
|
from common.utils.text import compass, day_range, hour_label, short_day
|
||||||
from crud.feed_crud import FeedCRUD
|
from crud.feed_crud import FeedCRUD
|
||||||
from crud.region_crud import RegionCRUD
|
from crud.region_crud import RegionCRUD
|
||||||
@@ -152,12 +152,12 @@ def feed_day(now: datetime) -> date:
|
|||||||
|
|
||||||
|
|
||||||
def feed_ttl_sec(now: datetime, sunset_at: datetime) -> int:
|
def feed_ttl_sec(now: datetime, sunset_at: datetime) -> int:
|
||||||
"""다음에 피드가 달라지는 시각까지. 시간대 경계·일몰(노을 카드가 내일 것으로)·03:00·예보·미세먼지 갱신 중 가장 빠른 쪽."""
|
"""다음에 피드가 달라지는 시각까지. 시간대 경계·일몰(노을 카드가 내일 것으로)·03:00·예보·초단기예보·미세먼지 갱신 중 가장 빠른 쪽."""
|
||||||
day = now.date()
|
day = now.date()
|
||||||
at = lambda d, h: datetime.combine(d, time(h), tzinfo=KST) # noqa: E731
|
at = lambda d, h: datetime.combine(d, time(h), tzinfo=KST) # noqa: E731
|
||||||
sunset = sunset_at.astimezone(KST)
|
sunset = sunset_at.astimezone(KST)
|
||||||
changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), sunset - timedelta(hours=2), sunset, sunset + NIGHT_AFTER_SUNSET,
|
changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), sunset - timedelta(hours=2), sunset, sunset + NIGHT_AFTER_SUNSET,
|
||||||
at(day + timedelta(days=1), _FEED_DAY_START), next_vilage_available(now)]
|
at(day + timedelta(days=1), _FEED_DAY_START), next_vilage_available(now), latest_ultra_base(now) + timedelta(hours=1) + ULTRA_DELAY]
|
||||||
air = now.replace(minute=20, second=0, microsecond=0)
|
air = now.replace(minute=20, second=0, microsecond=0)
|
||||||
changes.append(air if air > now else air + timedelta(hours=1))
|
changes.append(air if air > now else air + timedelta(hours=1))
|
||||||
nxt = min(c for c in changes if c > now)
|
nxt = min(c for c in changes if c > now)
|
||||||
|
|||||||
@@ -89,6 +89,18 @@ def test_feed_cache_expires_when_time_slot_changes():
|
|||||||
assert feed_ttl_sec(now, sunset) <= 600
|
assert feed_ttl_sec(now, sunset) <= 600
|
||||||
|
|
||||||
|
|
||||||
|
def test_feed_cache_expires_when_ultra_forecast_arrives():
|
||||||
|
"""초단기예보 비가 각 점수에 들어가니, 다음 초단기예보가 나오는 :45 에 캐시가 끝나야 한다."""
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from common.utils.kma_time import KST
|
||||||
|
from services.feed_service import feed_ttl_sec
|
||||||
|
|
||||||
|
now = datetime(2026, 10, 2, 13, 20, tzinfo=KST)
|
||||||
|
sunset = datetime(2026, 10, 2, 18, 10, tzinfo=KST)
|
||||||
|
assert feed_ttl_sec(now, sunset) == 25 * 60
|
||||||
|
|
||||||
|
|
||||||
def _card(post_type, post_id=1):
|
def _card(post_type, post_id=1):
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user