douyinWEB/scripts/_inspect_orphan_jobs.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

58 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
import sys
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
from app import db
db.init_db()
with db._lock:
conn = db._connect()
try:
rows = conn.execute(
"""
SELECT j.id, j.anchor_name, j.channel_pk, j.status, j.clip_path, j.upload_at,
c.id AS ch_id, c.name AS ch_name, c.enabled
FROM shorts_jobs j
LEFT JOIN shorts_channels c ON c.id = j.channel_pk
WHERE j.anchor_name LIKE '%菜场%'
OR IFNULL(c.name, '') LIKE '%菜场%'
OR (c.id IS NULL AND j.status IN ('scheduled','recorded','uploading','pending','failed'))
ORDER BY j.updated_at DESC
LIMIT 40
"""
).fetchall()
print("matches", len(rows))
for r in rows:
print(dict(r))
orphan = conn.execute(
"""
SELECT COUNT(*) AS c FROM shorts_jobs j
LEFT JOIN shorts_channels c ON c.id = j.channel_pk
WHERE c.id IS NULL OR TRIM(COALESCE(j.channel_pk, '')) = ''
"""
).fetchone()["c"]
print("orphan_count", orphan)
# Also show jobs where enrich would show empty channel (channel missing)
missing_ch = conn.execute(
"""
SELECT j.id, j.anchor_name, j.channel_pk, j.status, j.upload_at
FROM shorts_jobs j
LEFT JOIN shorts_channels c ON c.id = j.channel_pk
WHERE c.id IS NULL
ORDER BY j.updated_at DESC
LIMIT 20
"""
).fetchall()
print("missing_channel_jobs", len(missing_ch))
for r in missing_ch:
print(dict(r))
chs = conn.execute(
"SELECT id, name, enabled, oauth_profile_id FROM shorts_channels ORDER BY name"
).fetchall()
print("channels", len(chs))
for r in chs:
print(dict(r))
finally:
conn.close()