From 055eec69ef7a6f1ead50a70d3532ab5b01d45d5e Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Tue, 13 Oct 2026 09:25:26 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=94=BC=EB=93=9C=20=EC=BA=90=EC=8B=9C?= =?UTF-8?q?=EB=A5=BC=20=EB=8B=A4=EC=9D=8C=20=EC=B4=88=EB=8B=A8=EA=B8=B0?= =?UTF-8?q?=EC=98=88=EB=B3=B4=EA=B0=80=20=EB=82=98=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=81(:45)=EC=97=90=20=EB=81=9D=EB=82=B4=20?= =?UTF-8?q?=EB=B9=84=20=EB=B0=98=EC=98=81=20=EA=B0=81=20=EC=A0=90=EC=88=98?= =?UTF-8?q?=EA=B0=80=20=EB=8A=A6=EA=B2=8C=20=EB=B3=B4=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/feed_service.py | 6 +++--- backend/tests/test_feed.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/services/feed_service.py b/backend/services/feed_service.py index b2c4ce1..6596643 100644 --- a/backend/services/feed_service.py +++ b/backend/services/feed_service.py @@ -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.enums import AirGrade, ArticleCategory, ErrorType, PostType, RainType, RefType, Sky, SkyGrade, SkySituation, SkyType, WarningType 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 crud.feed_crud import FeedCRUD 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: - """다음에 피드가 달라지는 시각까지. 시간대 경계·일몰(노을 카드가 내일 것으로)·03:00·예보·미세먼지 갱신 중 가장 빠른 쪽.""" + """다음에 피드가 달라지는 시각까지. 시간대 경계·일몰(노을 카드가 내일 것으로)·03:00·예보·초단기예보·미세먼지 갱신 중 가장 빠른 쪽.""" day = now.date() at = lambda d, h: datetime.combine(d, time(h), tzinfo=KST) # noqa: E731 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, - 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) changes.append(air if air > now else air + timedelta(hours=1)) nxt = min(c for c in changes if c > now) diff --git a/backend/tests/test_feed.py b/backend/tests/test_feed.py index bfcee06..75cd592 100644 --- a/backend/tests/test_feed.py +++ b/backend/tests/test_feed.py @@ -89,6 +89,18 @@ def test_feed_cache_expires_when_time_slot_changes(): 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): from datetime import datetime