#!/bin/bash # Pipeline Queue Monitor Script # Usage: ./monitor_pipeline_queue.sh API_KEY="muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69" DB="momentry" echo "===================================" echo "Pipeline Queue Monitor" echo "Time: $(date '+%Y-%m-%d %H:%M:%S')" echo "===================================" echo "" # Queue Statistics echo "📊 Queue Statistics:" echo "---" /opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d $DB -c " SELECT queue_name, status, COUNT(*) as count FROM command_queue GROUP BY queue_name, status ORDER BY queue_name, status; " 2>/dev/null echo "" # Processing Commands echo "⏳ Processing Commands:" echo "---" /opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d $DB -c " SELECT message_id, command_category, processing_started_at, NOW() - processing_started_at as duration FROM command_queue WHERE status = 'processing' ORDER BY processing_started_at; " 2>/dev/null echo "" # Recent Failed Commands echo "❌ Recent Failed Commands (last 10):" echo "---" /opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d $DB -c " SELECT message_id, command_category, LEFT(last_error, 80) as error_preview FROM command_queue WHERE status = 'failed' ORDER BY created_at DESC LIMIT 10; " 2>/dev/null echo "" # Worker Status echo "🔄 Worker Status:" echo "---" echo "Pipeline Worker: $(ps aux | grep pipeline_worker | grep -v grep | awk '{print "Running (PID "$2")"}' || echo 'Not running')" echo "Job Worker: $(ps aux | grep 'momentry worker' | grep -v grep | awk '{print "Running (PID "$2")"}' || echo 'Not running')" echo "" echo "===================================" echo "Commands:" echo " Reset stuck: /opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d $DB -c \"UPDATE command_queue SET status = 'pending', processing_started_at = NULL WHERE status = 'processing';\"" echo " View logs: tail -f /Users/accusys/momentry_core/logs/pipeline_worker.log" echo "==================================="