feat: implement task queue statistics and add UI templates for job management and visualization.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user