|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import asyncio
|
|
|
from datetime import date, timedelta
|
|
from datetime import date, timedelta
|
|
|
from typing import Callable, TYPE_CHECKING
|
|
from typing import Callable, TYPE_CHECKING
|
|
|
from fastapi import APIRouter, BackgroundTasks, HTTPException
|
|
from fastapi import APIRouter, BackgroundTasks, HTTPException
|
|
@@ -81,17 +82,23 @@ async def workflow_delete_discount(target_date: date, bg: BackgroundTasks):
|
|
|
await delete_discount(target_date, schedule=lambda c: bg.add_task(_bg, c))
|
|
await delete_discount(target_date, schedule=lambda c: bg.add_task(_bg, c))
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def _periodic_fetch_short(api: 'ServiceAPI') -> None:
|
|
|
|
|
|
|
+async def _periodic_sync_short(api: 'ServiceAPI') -> None:
|
|
|
start = local_today()
|
|
start = local_today()
|
|
|
- window = get_config().global_.reservation_window_days
|
|
|
|
|
- await fetch_prices(start, start + timedelta(days=window), api=api)
|
|
|
|
|
|
|
+ end = start + timedelta(days=get_config().global_.reservation_window_days)
|
|
|
|
|
+ await asyncio.gather(
|
|
|
|
|
+ fetch_prices(start, end, api=api),
|
|
|
|
|
+ push_prices(start, end, api=api),
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def _periodic_fetch_long(api: 'ServiceAPI') -> None:
|
|
|
|
|
|
|
+async def _periodic_sync_long(api: 'ServiceAPI') -> None:
|
|
|
start = local_today()
|
|
start = local_today()
|
|
|
- window = get_config().global_.long_window_days
|
|
|
|
|
- await fetch_prices(start, start + timedelta(days=window), api=api)
|
|
|
|
|
|
|
+ end = start + timedelta(days=get_config().global_.long_window_days)
|
|
|
|
|
+ await asyncio.gather(
|
|
|
|
|
+ fetch_prices(start, end, api=api),
|
|
|
|
|
+ push_prices(start, end, api=api),
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
|
|
|
-register_periodic(_periodic_fetch_short, timedelta(hours=6))
|
|
|
|
|
-register_periodic(_periodic_fetch_long, timedelta(days=1))
|
|
|
|
|
|
|
+register_periodic(_periodic_sync_short, timedelta(hours=6))
|
|
|
|
|
+register_periodic(_periodic_sync_long, timedelta(days=1))
|