Compare commits
8 Commits
bdcb7a476c
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
796e1fe454 | ||
| 84c59a3b64 | |||
|
|
dc9d4d7327 | ||
| 77cf817568 | |||
|
|
0f6a30f01c | ||
| 77b0963fa4 | |||
|
|
f39e39156a | ||
| deb18f1e32 |
@@ -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() {
|
||||||
|
|||||||
@@ -202,9 +202,10 @@ update_queue_item_state() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local issue_ref=$(python3 -c "import json; print(json.load(open('$item_file')).get('issue_ref', ''))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
python3 << PYEOF
|
python3 << PYEOF
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
item_file = "$item_file"
|
item_file = "$item_file"
|
||||||
@@ -215,8 +216,6 @@ pid = "$pid"
|
|||||||
with open(item_file, 'r') as f:
|
with open(item_file, 'r') as f:
|
||||||
item = json.load(f)
|
item = json.load(f)
|
||||||
|
|
||||||
issue_ref = item.get('issue_ref', '')
|
|
||||||
|
|
||||||
item['state'] = new_state
|
item['state'] = new_state
|
||||||
|
|
||||||
if new_state == "notified":
|
if new_state == "notified":
|
||||||
@@ -227,14 +226,18 @@ if new_state == "notified":
|
|||||||
item['pid'] = int(pid) if pid.isdigit() else None
|
item['pid'] = int(pid) if pid.isdigit() else None
|
||||||
elif new_state == "completed":
|
elif new_state == "completed":
|
||||||
item['completed_at'] = datetime.now().isoformat() + "Z"
|
item['completed_at'] = datetime.now().isoformat() + "Z"
|
||||||
os.system(f"kugetsu_add_notification 'task_completed' 'Task completed: {issue_ref}' '{issue_ref}'")
|
|
||||||
elif new_state == "error":
|
elif new_state == "error":
|
||||||
item['error'] = datetime.now().isoformat() + "Z"
|
item['error'] = datetime.now().isoformat() + "Z"
|
||||||
os.system(f"kugetsu_add_notification 'task_error' 'Task error: {issue_ref}' '{issue_ref}'")
|
|
||||||
|
|
||||||
with open(item_file, 'w') as f:
|
with open(item_file, 'w') as f:
|
||||||
json.dump(item, f, indent=2)
|
json.dump(item, f, indent=2)
|
||||||
|
|
||||||
print(f"Updated $queue_id to state: $new_state")
|
print(f"Updated $queue_id to state: $new_state")
|
||||||
PYEOF
|
PYEOF
|
||||||
|
|
||||||
|
if [ "$new_state" = "completed" ]; then
|
||||||
|
kugetsu_add_notification "task_completed" "Task completed: $issue_ref" "$issue_ref"
|
||||||
|
elif [ "$new_state" = "error" ]; then
|
||||||
|
kugetsu_add_notification "task_error" "Task error: $issue_ref" "$issue_ref"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user