Compare commits
4 Commits
fix/issue-
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59f6a4883e | ||
| 9667c3e800 | |||
|
|
796e1fe454 | ||
| 84c59a3b64 |
@@ -361,55 +361,6 @@ get_queue_stats() {
|
|||||||
echo "{\"total\": $total, \"pending\": $pending, \"notified\": $notified, \"completed\": $completed, \"error\": $error}"
|
echo "{\"total\": $total, \"pending\": $pending, \"notified\": $notified, \"completed\": $completed, \"error\": $error}"
|
||||||
}
|
}
|
||||||
|
|
||||||
update_queue_item_state() {
|
|
||||||
local queue_id="$1"
|
|
||||||
local new_state="$2"
|
|
||||||
local session_id="${3:-}"
|
|
||||||
local pid="${4:-}"
|
|
||||||
|
|
||||||
local item_file="$QUEUE_ITEMS_DIR/${queue_id}.json"
|
|
||||||
if [ ! -f "$item_file" ]; then
|
|
||||||
echo "Error: Queue item not found: $queue_id" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
python3 << PYEOF
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
item_file = "$item_file"
|
|
||||||
new_state = "$new_state"
|
|
||||||
session_id = "$session_id"
|
|
||||||
pid = "$pid"
|
|
||||||
|
|
||||||
with open(item_file, 'r') as f:
|
|
||||||
item = json.load(f)
|
|
||||||
|
|
||||||
issue_ref = item.get('issue_ref', '')
|
|
||||||
|
|
||||||
item['state'] = new_state
|
|
||||||
|
|
||||||
if new_state == "notified":
|
|
||||||
item['notified_at'] = datetime.now().isoformat() + "Z"
|
|
||||||
if session_id:
|
|
||||||
item['opencode_session_id'] = session_id
|
|
||||||
if pid:
|
|
||||||
item['pid'] = int(pid) if pid.isdigit() else None
|
|
||||||
elif new_state == "completed":
|
|
||||||
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":
|
|
||||||
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:
|
|
||||||
json.dump(item, f, indent=2)
|
|
||||||
|
|
||||||
print(f"Updated $queue_id to state: $new_state")
|
|
||||||
PYEOF
|
|
||||||
}
|
|
||||||
|
|
||||||
check_task_timeouts() {
|
check_task_timeouts() {
|
||||||
if [ ! -d "$QUEUE_ITEMS_DIR" ]; then
|
if [ ! -d "$QUEUE_ITEMS_DIR" ]; then
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -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