Skip to content

Commit 0e7ac0a

Browse files
committed
Log search timestamps in KST
1 parent 7a00753 commit 0e7ac0a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/services/worker_bridge.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import uuid
1010
import threading
1111
from dataclasses import asdict
12-
from datetime import datetime
12+
from datetime import datetime, timedelta, timezone
1313
from typing import Any, Dict, List, Optional
1414

1515
from app.schemas.search import (
@@ -63,18 +63,24 @@ def _serialize_result(result: SearchResult) -> Dict[str, Any]:
6363
}
6464

6565

66+
def _now_kst() -> datetime:
67+
return datetime.now(timezone(timedelta(hours=9)))
68+
69+
6670
def _build_search_log_payload(
6771
req: SearchRequest,
6872
response: SearchResponse,
6973
*,
7074
job_id: str,
7175
worker_id: str,
7276
elapsed_ms: int,
77+
now: datetime | None = None,
7378
) -> Dict[str, Any]:
7479
meta = get_request_meta()
7580
query = response.query
81+
now = now or _now_kst()
7682
payload = {
77-
"timestamp": datetime.utcnow().isoformat(),
83+
"timestamp": now.isoformat(),
7884
"search_id": response.search_id or "",
7985
"job_id": job_id,
8086
"worker_id": worker_id,
@@ -378,14 +384,16 @@ async def run_worker_search(req: SearchRequest) -> SearchResponse:
378384
)
379385
if s3_logs_enabled():
380386
try:
387+
now = _now_kst()
381388
payload = _build_search_log_payload(
382389
req,
383390
response,
384391
job_id=job_id,
385392
worker_id=worker_id,
386393
elapsed_ms=elapsed_ms,
394+
now=now,
387395
)
388-
date_tag = datetime.utcnow().strftime("%Y/%m/%d")
396+
date_tag = now.strftime("%Y/%m/%d")
389397
_upload_text_async(
390398
f"search_usage/{date_tag}/{uuid.uuid4().hex}.json",
391399
json.dumps(payload, ensure_ascii=False),

0 commit comments

Comments
 (0)