70 lines
2.9 KiB
Python
70 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Diagnose why only 6/135 uploaded — upload_at spread + gaps."""
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r'''
|
|
import sqlite3, time, datetime, json
|
|
from collections import Counter
|
|
BJ=datetime.timezone(datetime.timedelta(hours=8))
|
|
now=time.time()
|
|
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
|
|
con.row_factory=sqlite3.Row
|
|
day=datetime.datetime.now(BJ).strftime('%Y-%m-%d')
|
|
print('day', day, 'now_bj', datetime.datetime.now(BJ).isoformat())
|
|
# settings
|
|
for k in ('shorts_upload_min_gap_sec','shorts_channel_min_gap_sec','shorts_max_concurrent','shorts_upload_max_concurrent','shorts_upload_spread','shorts_auto_upload'):
|
|
r=con.execute('SELECT value FROM kv_settings WHERE key=?',(k,)).fetchone()
|
|
print('kv', k, r[0] if r else None)
|
|
# job status counts
|
|
rows=con.execute('SELECT status, COUNT(*) c FROM shorts_jobs WHERE push_date=? GROUP BY status',(day,)).fetchall()
|
|
print('jobs', dict(rows))
|
|
# scheduled with clip: upload_at histogram by hour BJ
|
|
sched=con.execute("""SELECT upload_at, status, channel_pk, clip_path FROM shorts_jobs
|
|
WHERE push_date=? AND status IN ('scheduled','recorded')""",(day,)).fetchall()
|
|
hours=Counter(); due=0; future=0; no_clip=0
|
|
for r in sched:
|
|
clip=str(r['clip_path'] or '').strip()
|
|
if not clip:
|
|
no_clip+=1
|
|
continue
|
|
ua=float(r['upload_at'] or 0)
|
|
if ua<=0:
|
|
hours['no_at']+=1
|
|
continue
|
|
if ua<=now+60: due+=1
|
|
else: future+=1
|
|
h=datetime.datetime.fromtimestamp(ua,BJ).hour
|
|
hours[h]+=1
|
|
print('clip_ready scheduled/recorded', len(sched)-no_clip, 'no_clip', no_clip, 'due_now', due, 'future', future)
|
|
print('upload_at by hour BJ', dict(sorted(hours.items())))
|
|
# uploaded count
|
|
up=con.execute("SELECT COUNT(*) FROM shorts_jobs WHERE push_date=? AND status IN ('uploaded','done')",(day,)).fetchone()[0]
|
|
print('uploaded', up)
|
|
# channels
|
|
chs=con.execute('SELECT COUNT(*) FROM shorts_channels WHERE enabled=1').fetchone()[0]
|
|
print('enabled_channels', chs)
|
|
# next 10 due
|
|
print('=== next upload slots ===')
|
|
for r in con.execute("""SELECT id, upload_at, status, channel_pk FROM shorts_jobs
|
|
WHERE push_date=? AND status IN ('scheduled','recorded') AND IFNULL(clip_path,'')!=''
|
|
ORDER BY CASE WHEN upload_at<=0 THEN 1e18 ELSE upload_at END ASC LIMIT 12""",(day,)):
|
|
ua=float(r['upload_at'] or 0)
|
|
bj=datetime.datetime.fromtimestamp(ua,BJ).strftime('%H:%M:%S') if ua>0 else '-'
|
|
print(bj, 'in', int(ua-now) if ua else '?', 's', r['status'], str(r['channel_pk'])[:8])
|
|
con.close()
|
|
'''
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
_, o, e = c.exec_command("python3 - <<'PY'\n" + REMOTE + "\nPY", timeout=60)
|
|
print(o.read().decode("utf-8", "replace"))
|
|
err = e.read().decode("utf-8", "replace")
|
|
if err:
|
|
print("STDERR", err[:1000])
|
|
c.close()
|