25 lines
673 B
Python
25 lines
673 B
Python
import time
|
|
import logging
|
|
from typing import Optional
|
|
from app.database import pool
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
async def track_usage(
|
|
user_id: str,
|
|
action: str,
|
|
store_id: Optional[str] = None,
|
|
tokens: int = 0,
|
|
duration: float = 0
|
|
):
|
|
try:
|
|
async with pool.acquire() as conn:
|
|
await conn.execute(
|
|
"""INSERT INTO usage_stats
|
|
(user_id, store_id, action, tokens, duration)
|
|
VALUES ($1, $2, $3, $4, $5)""",
|
|
user_id, store_id, action, tokens, round(duration, 3)
|
|
)
|
|
except Exception as e:
|
|
logger.error(f"Tracking Fehler: {e}")
|