chore: structured timestamped logging across the backend
- uvicorn --log-config (log_config.json): timestamped formatters for uvicorn access/error and the app's own "subfeed" loggers (ms precision) - Log key activity: startup/shutdown, login/denied, token refresh, YouTube API errors, subscription imports, sync pause/resume - Background sync jobs no longer swallow errors silently — failures in RSS poll, backfill, enrichment, autotag and resync are logged with tracebacks
This commit is contained in:
parent
ecaf516429
commit
f6c5488566
9 changed files with 86 additions and 7 deletions
|
|
@ -5,11 +5,14 @@ detection over a sample of recent video titles. Topics are mapped from YouTube's
|
|||
topicDetails categories and the channel's dominant video category. System tags are
|
||||
regenerated freely; user tags are never touched here.
|
||||
"""
|
||||
import logging
|
||||
import re
|
||||
|
||||
from sqlalchemy import and_, exists, func, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
log = logging.getLogger("subfeed.autotag")
|
||||
|
||||
from app.config import settings
|
||||
from app.models import Channel, ChannelTag, Tag, Video
|
||||
|
||||
|
|
@ -273,6 +276,7 @@ def run_autotag_all(db: Session, only_missing: bool = False) -> dict:
|
|||
tagged += 1
|
||||
except Exception:
|
||||
db.rollback()
|
||||
log.exception("Auto-tagging failed for channel %s", channel.id)
|
||||
removed = _cleanup_orphan_system_tags(db)
|
||||
return {"channels_tagged": tagged, "orphan_tags_removed": removed}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,15 @@ Channel/video data is shared across users, so background work acts through a "se
|
|||
user" (any user with a stored refresh token) unless a YOUTUBE_API_KEY is configured for
|
||||
public reads.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app import quota
|
||||
from app.config import settings
|
||||
|
||||
log = logging.getLogger("subfeed.sync")
|
||||
from app.models import Channel, OAuthToken, User
|
||||
from app.sync.subscriptions import import_subscriptions
|
||||
from app.sync.videos import (
|
||||
|
|
@ -43,6 +47,7 @@ def run_rss_poll(db: Session, channels: list[Channel] | None = None) -> int:
|
|||
new += poll_rss_channel(db, channel)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
log.exception("RSS poll failed for channel %s", channel.id)
|
||||
return new
|
||||
|
||||
|
||||
|
|
@ -83,6 +88,7 @@ def run_subscription_resync(db: Session) -> dict:
|
|||
import_subscriptions(db, user)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
log.exception("Subscription resync failed for user %s", user.id)
|
||||
return {"users": len(users)}
|
||||
|
||||
|
||||
|
|
@ -111,6 +117,7 @@ def run_recent_backfill(
|
|||
processed += 1
|
||||
except Exception:
|
||||
db.rollback()
|
||||
log.exception("Recent backfill failed for channel %s", channel.id)
|
||||
return {"channels_processed": processed, "videos_added": videos_added}
|
||||
|
||||
|
||||
|
|
@ -139,4 +146,5 @@ def run_deep_backfill(db: Session, max_channels: int = 10, max_pages: int = 5) -
|
|||
processed += 1
|
||||
except Exception:
|
||||
db.rollback()
|
||||
log.exception("Deep backfill failed for channel %s", channel.id)
|
||||
return {"channels_processed": processed, "videos_added": videos_added}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
"""Import the authenticated user's YouTube subscriptions and channel metadata."""
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import select
|
||||
|
|
@ -7,6 +8,8 @@ from sqlalchemy.orm import Session
|
|||
from app.models import Channel, Subscription, User
|
||||
from app.youtube.client import YouTubeClient, best_thumbnail
|
||||
|
||||
log = logging.getLogger("subfeed.sync")
|
||||
|
||||
|
||||
def _to_int(value) -> int | None:
|
||||
try:
|
||||
|
|
@ -107,9 +110,11 @@ def import_subscriptions(db: Session, user: User) -> dict:
|
|||
detailed = len(items)
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
result = {
|
||||
"subscriptions": len(fetched),
|
||||
"channels_new": new_channels,
|
||||
"channels_detailed": detailed,
|
||||
"removed_stale": removed,
|
||||
}
|
||||
log.info("Subscription import (user %s): %s", user.id, result)
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue