More logging
This commit is contained in:
@@ -4,6 +4,7 @@ Handles time-series data with metadata caching.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, date
|
||||
from typing import Any, Dict, List, Optional
|
||||
@@ -11,6 +12,9 @@ from typing import Any, Dict, List, Optional
|
||||
import asyncpg
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Set up logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TimescaleDBClient:
|
||||
"""Async client for TimescaleDB operations with metadata caching."""
|
||||
@@ -171,6 +175,11 @@ class TimescaleDBClient:
|
||||
status: Campaign status
|
||||
objective: Campaign objective
|
||||
"""
|
||||
logger.info(
|
||||
f"upsert_campaign called: campaign_id={campaign_id}, account_id={account_id}, "
|
||||
f"campaign_name={campaign_name!r}, status={status}, objective={objective}"
|
||||
)
|
||||
|
||||
query = """
|
||||
INSERT INTO campaigns (campaign_id, account_id, campaign_name, status, objective, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, NOW())
|
||||
@@ -181,8 +190,23 @@ class TimescaleDBClient:
|
||||
objective = COALESCE(EXCLUDED.objective, campaigns.objective),
|
||||
updated_at = NOW()
|
||||
"""
|
||||
|
||||
logger.debug(f"Executing query with params: {[campaign_id, account_id, campaign_name, status, objective]}")
|
||||
|
||||
async with self.pool.acquire() as conn:
|
||||
await conn.execute(query, campaign_id, account_id, campaign_name, status, objective)
|
||||
result = await conn.execute(query, campaign_id, account_id, campaign_name, status, objective)
|
||||
logger.debug(f"Query result: {result}")
|
||||
|
||||
# Query back what was actually stored
|
||||
stored = await conn.fetchrow(
|
||||
"SELECT campaign_name, status, objective FROM campaigns WHERE campaign_id = $1",
|
||||
campaign_id
|
||||
)
|
||||
logger.info(
|
||||
f"After upsert, database contains: campaign_id={campaign_id}, "
|
||||
f"campaign_name={stored['campaign_name']!r}, status={stored['status']}, "
|
||||
f"objective={stored['objective']}"
|
||||
)
|
||||
|
||||
async def upsert_adset(
|
||||
self,
|
||||
|
||||
@@ -347,7 +347,7 @@ class ScheduledInsightsGrabber:
|
||||
campaign_dict = dict(campaign)
|
||||
|
||||
# DEBUG: Log all campaign data before upsert
|
||||
logger.info(
|
||||
logger.debug(
|
||||
f"Campaign metadata before upsert: id={campaign_id}, "
|
||||
f"name={campaign_name!r}, status={campaign.get('status')}, "
|
||||
f"objective={campaign.get('objective')}, raw={campaign_dict}"
|
||||
|
||||
Reference in New Issue
Block a user