feat: Add car availability check feature
- Add daily scheduled check for Carmodoo car availability - Add manual trigger button in admin settings - Mark sold cars as soldout=True automatically - Add settings for check time and enable/disable toggle - Display check status and statistics in admin UI 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ from .api import cars, auth, inquiries, hero_banners, carmodoo, translations, cc
|
||||
from .config import get_settings
|
||||
from .services.exchange_rate_service import update_exchange_rates
|
||||
from .services.visitor_service import aggregate_daily_stats, cleanup_old_visitor_logs
|
||||
from .services.car_availability_service import run_car_availability_check
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
app_settings = get_settings()
|
||||
@@ -103,6 +104,19 @@ async def scheduled_cleanup_old_visitor_logs():
|
||||
db.close()
|
||||
|
||||
|
||||
async def scheduled_car_availability_check():
|
||||
"""Check car availability on Carmodoo"""
|
||||
print("[Scheduler] Starting car availability check...")
|
||||
db = SessionLocal()
|
||||
try:
|
||||
result = await run_car_availability_check(db)
|
||||
print(f"[Scheduler] Car availability check completed: {result}")
|
||||
except Exception as e:
|
||||
print(f"[Scheduler] Car availability check failed: {e}")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""앱 시작/종료 시 실행되는 lifespan 이벤트"""
|
||||
@@ -136,8 +150,28 @@ async def lifespan(app: FastAPI):
|
||||
replace_existing=True
|
||||
)
|
||||
|
||||
# 차량 판매상태 검증 (매일 새벽 6시 - 설정에서 변경 가능)
|
||||
# 동적 시간 설정을 위해 settings 확인
|
||||
db = SessionLocal()
|
||||
try:
|
||||
from .models.settings import SystemSettings
|
||||
settings = db.query(SystemSettings).first()
|
||||
check_hour = settings.car_availability_check_hour if settings else 6
|
||||
except:
|
||||
check_hour = 6
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
scheduler.add_job(
|
||||
scheduled_car_availability_check,
|
||||
CronTrigger(hour=check_hour, minute=0),
|
||||
id="daily_car_availability_check",
|
||||
name="Daily Car Availability Check",
|
||||
replace_existing=True
|
||||
)
|
||||
|
||||
scheduler.start()
|
||||
print("[Startup] Scheduler started - Exchange rates: 11:30 AM, Visitor stats: 2:00 AM, Log cleanup: Sunday 3:00 AM")
|
||||
print(f"[Startup] Scheduler started - Exchange rates: 11:30 AM, Visitor stats: 2:00 AM, Log cleanup: Sunday 3:00 AM, Car availability: {check_hour}:00 AM")
|
||||
|
||||
# 서버 시작 시 환율 데이터 초기화 (백그라운드에서)
|
||||
asyncio.create_task(scheduled_update_exchange_rates())
|
||||
|
||||
Reference in New Issue
Block a user