|
9 | 9 | import uuid |
10 | 10 | import threading |
11 | 11 | from dataclasses import asdict |
12 | | -from datetime import datetime |
| 12 | +from datetime import datetime, timedelta, timezone |
13 | 13 | from typing import Any, Dict, List, Optional |
14 | 14 |
|
15 | 15 | from app.schemas.search import ( |
@@ -63,18 +63,24 @@ def _serialize_result(result: SearchResult) -> Dict[str, Any]: |
63 | 63 | } |
64 | 64 |
|
65 | 65 |
|
| 66 | +def _now_kst() -> datetime: |
| 67 | + return datetime.now(timezone(timedelta(hours=9))) |
| 68 | + |
| 69 | + |
66 | 70 | def _build_search_log_payload( |
67 | 71 | req: SearchRequest, |
68 | 72 | response: SearchResponse, |
69 | 73 | *, |
70 | 74 | job_id: str, |
71 | 75 | worker_id: str, |
72 | 76 | elapsed_ms: int, |
| 77 | + now: datetime | None = None, |
73 | 78 | ) -> Dict[str, Any]: |
74 | 79 | meta = get_request_meta() |
75 | 80 | query = response.query |
| 81 | + now = now or _now_kst() |
76 | 82 | payload = { |
77 | | - "timestamp": datetime.utcnow().isoformat(), |
| 83 | + "timestamp": now.isoformat(), |
78 | 84 | "search_id": response.search_id or "", |
79 | 85 | "job_id": job_id, |
80 | 86 | "worker_id": worker_id, |
@@ -378,14 +384,16 @@ async def run_worker_search(req: SearchRequest) -> SearchResponse: |
378 | 384 | ) |
379 | 385 | if s3_logs_enabled(): |
380 | 386 | try: |
| 387 | + now = _now_kst() |
381 | 388 | payload = _build_search_log_payload( |
382 | 389 | req, |
383 | 390 | response, |
384 | 391 | job_id=job_id, |
385 | 392 | worker_id=worker_id, |
386 | 393 | elapsed_ms=elapsed_ms, |
| 394 | + now=now, |
387 | 395 | ) |
388 | | - date_tag = datetime.utcnow().strftime("%Y/%m/%d") |
| 396 | + date_tag = now.strftime("%Y/%m/%d") |
389 | 397 | _upload_text_async( |
390 | 398 | f"search_usage/{date_tag}/{uuid.uuid4().hex}.json", |
391 | 399 | json.dumps(payload, ensure_ascii=False), |
|
0 commit comments