feat: implement task queue statistics and add UI templates for job management and visualization.

This commit is contained in:
2026-08-15 00:00:41 -07:00
parent 5510e3ac82
commit 286278c1ec
12 changed files with 1144 additions and 644 deletions
+26
View File
@@ -7,6 +7,32 @@ import (
"log"
)
// QueueStats holds task queue counters
type QueueStats struct {
Pending int `json:"pending"`
Running int `json:"running"`
Failed int `json:"failed"`
Completed int `json:"completed"`
}
// GetQueueStats returns counts for each task status
func (db *DB) GetQueueStats() (*QueueStats, error) {
query := `
SELECT
COALESCE(SUM(CASE WHEN status = 'PENDING' THEN 1 ELSE 0 END), 0),
COALESCE(SUM(CASE WHEN status = 'RUNNING' THEN 1 ELSE 0 END), 0),
COALESCE(SUM(CASE WHEN status = 'FAILED' THEN 1 ELSE 0 END), 0),
COALESCE(SUM(CASE WHEN status = 'COMPLETED' THEN 1 ELSE 0 END), 0)
FROM tasks
`
var stats QueueStats
err := db.QueryRow(query).Scan(&stats.Pending, &stats.Running, &stats.Failed, &stats.Completed)
if err != nil {
return nil, err
}
return &stats, nil
}
// EnqueueTask adds a new task to the queue
func (db *DB) EnqueueTask(taskType string, payload interface{}) error {
payloadBytes, err := json.Marshal(payload)