101 lines
3.8 KiB
Python
101 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Why claim_due returns nothing while 64 scheduled are due."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r'''
|
|
python3 <<'PY'
|
|
import sqlite3, time, os
|
|
from pathlib import Path
|
|
conn=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
|
|
conn.row_factory=sqlite3.Row
|
|
day='2026-09-09'
|
|
now=time.time()
|
|
rows=conn.execute("""
|
|
SELECT j.id,j.status,j.channel_pk,j.upload_at,j.clip_path,j.youtube_video_id,j.error,
|
|
c.name,c.enabled,c.oauth_profile_id
|
|
FROM shorts_jobs j
|
|
LEFT JOIN shorts_channels c ON c.id=j.channel_pk
|
|
WHERE j.push_date=? AND j.status IN ('scheduled','recorded')
|
|
ORDER BY j.upload_at ASC LIMIT 20
|
|
""",(day,)).fetchall()
|
|
print('sample due-ish')
|
|
for r in rows:
|
|
clip=str(r['clip_path'] or '')
|
|
exists=bool(clip) and Path(clip).is_file()
|
|
print(f" {r['status']} due={float(r['upload_at'] or 0)<=now} clip_ok={exists} en={r['enabled']} vid={bool(r['youtube_video_id'])} name={r['name']} path={clip[-40:] if clip else ''}")
|
|
|
|
# claim eligibility counts
|
|
elig=conn.execute("""
|
|
SELECT COUNT(*) c FROM shorts_jobs j
|
|
INNER JOIN shorts_channels c ON c.id=j.channel_pk
|
|
WHERE j.push_date=? AND j.status='scheduled' AND c.enabled=1
|
|
AND j.clip_path!='' AND j.youtube_video_id='' AND j.upload_at>0 AND j.upload_at<=?
|
|
""",(day,now)).fetchone()['c']
|
|
print('claim_eligible_scheduled', elig)
|
|
|
|
# per channel last upload + gap
|
|
chs=conn.execute('SELECT id,name FROM shorts_channels WHERE enabled=1').fetchall()
|
|
blocked=0
|
|
ok=0
|
|
for ch in chs:
|
|
last=conn.execute("""
|
|
SELECT status, finished_at, updated_at, upload_at FROM shorts_jobs
|
|
WHERE channel_pk=? AND push_date=? AND status IN ('uploading','uploaded','done')
|
|
ORDER BY COALESCE(NULLIF(finished_at,0), updated_at) DESC LIMIT 1
|
|
""",(ch['id'],day)).fetchone()
|
|
last_ts=0
|
|
if last:
|
|
st=last['status']
|
|
if st in ('uploaded','done'):
|
|
last_ts=float(last['finished_at'] or last['updated_at'] or 0)
|
|
else:
|
|
last_ts=float(last['updated_at'] or last['upload_at'] or 0)
|
|
gap=now-last_ts if last_ts else 9999
|
|
due_ch=conn.execute("""
|
|
SELECT COUNT(*) c FROM shorts_jobs j
|
|
WHERE channel_pk=? AND push_date=? AND status IN ('scheduled','recorded')
|
|
AND clip_path!='' AND upload_at<=? AND youtube_video_id=''
|
|
""",(ch['id'],day,now)).fetchone()['c']
|
|
if due_ch and gap<600:
|
|
blocked+=1
|
|
print(f"GAP_BLOCK {ch['name']} gap={int(gap)}s due={due_ch} last_ts={last_ts}")
|
|
elif due_ch:
|
|
ok+=1
|
|
print(f"READY {ch['name']} gap={int(gap)}s due={due_ch}")
|
|
print('channels_ready', ok, 'channels_gap_blocked', blocked)
|
|
|
|
# auto upload setting
|
|
for k in ('shorts_auto_upload','shorts_enabled','shorts_upload_max_concurrent'):
|
|
r=conn.execute('SELECT value FROM kv_settings WHERE key=?',(k,)).fetchone()
|
|
print('kv',k, r['value'] if r else None)
|
|
|
|
# pipeline process
|
|
import subprocess
|
|
print(subprocess.getoutput('systemctl is-active douyinweb-api; ps aux | grep -E "[u]vicorn|[s]horts" | head -5'))
|
|
# try claim in-process
|
|
import sys
|
|
sys.path.insert(0,'/opt/douyinWEB/backend')
|
|
os.chdir('/opt/douyinWEB/backend')
|
|
from app import db
|
|
j=db.claim_due_shorts_upload()
|
|
print('claim_result', (j or {}).get('id'), (j or {}).get('status'), (j or {}).get('channel_pk'))
|
|
if j:
|
|
# roll back? leave as uploading — worker should pick; or revert
|
|
db.update_shorts_job(j['id'], status='scheduled', error='')
|
|
print('reverted to scheduled for safety')
|
|
conn.close()
|
|
PY
|
|
'''
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
_, o, e = c.exec_command(REMOTE, timeout=90)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|