-- 检查任务队列状态
SELECT 
    'task_queue' as table_name,
    status,
    COUNT(*) as count
FROM task_queue 
GROUP BY status
UNION ALL
SELECT 
    'image_to_video_tasks' as table_name,
    status,
    COUNT(*) as count
FROM image_to_video_tasks 
GROUP BY status;

-- 查看最近的任务
SELECT 
    'Recent Task Queue' as info,
    task_id,
    username,
    task_type,
    status,
    real_task_id,
    check_count,
    error_message,
    created_at
FROM task_queue 
ORDER BY created_at DESC 
LIMIT 10;

-- 查看最近的图生视频任务
SELECT 
    'Recent Image Tasks' as info,
    task_id,
    username,
    status,
    progress,
    real_task_id,
    error_message,
    first_frame_url,
    created_at
FROM image_to_video_tasks 
ORDER BY created_at DESC 
LIMIT 10;

-- 查看失败的任务详情
SELECT 
    'Failed Tasks' as info,
    tq.task_id,
    tq.username,
    tq.status as queue_status,
    tq.error_message as queue_error,
    it.status as task_status,
    it.error_message as task_error,
    it.first_frame_url,
    tq.created_at
FROM task_queue tq
LEFT JOIN image_to_video_tasks it ON tq.task_id = it.task_id
WHERE tq.status = 'FAILED' OR it.status = 'FAILED'
ORDER BY tq.created_at DESC;

