fix(kugetsu): return proper JSON array from get_pending_tasks() #163

Merged
shoko merged 1 commits from fix/issue-155-queue-list-json into main 2026-04-06 01:45:10 +02:00

View File

@@ -310,12 +310,31 @@ get_pending_tasks() {
return return
fi fi
find "$QUEUE_ITEMS_DIR" -name "*.json" -type f 2>/dev/null | while read -r file; do python3 -c "
local state=$(python3 -c "import json; print(json.load(open('$file')).get('state', ''))" 2>/dev/null || echo "") import json
if [ "$state" = "pending" ]; then import os
cat "$file" import sys
fi
done | head -"$limit" queue_dir = os.environ.get('QUEUE_ITEMS_DIR', '')
limit = int(sys.argv[1]) if len(sys.argv) > 1 else 10
items = []
if os.path.isdir(queue_dir):
for filename in os.listdir(queue_dir):
if filename.endswith('.json'):
filepath = os.path.join(queue_dir, filename)
try:
with open(filepath) as f:
data = json.load(f)
if data.get('state') == 'pending':
items.append(data)
if len(items) >= limit:
break
except:
pass
print(json.dumps(items))
" "$limit"
} }
get_queue_stats() { get_queue_stats() {