Fix queue stats to properly distinguish cancelled from failed jobs

The queue Stats() method was grouping cancelled and failed jobs together,
causing cancelled jobs to be displayed as "failed" in the status bar.
Updated Stats() to return a separate cancelled count and modified all
callers (updateStatsBar, queueProgressCounts, showMainMenu) to handle
the new return value. Also updated ConversionStatsBar to display
cancelled jobs separately in the status bar.
This commit is contained in:
Stu Leak 2025-12-17 14:25:18 -05:00
parent 3e5911d607
commit 9aeb82dd2b
3 changed files with 18 additions and 9 deletions

View File

@ -167,7 +167,7 @@ func (q *Queue) List() []*Job {
} }
// Stats returns queue statistics // Stats returns queue statistics
func (q *Queue) Stats() (pending, running, completed, failed int) { func (q *Queue) Stats() (pending, running, completed, failed, cancelled int) {
q.mu.RLock() q.mu.RLock()
defer q.mu.RUnlock() defer q.mu.RUnlock()
@ -179,8 +179,10 @@ func (q *Queue) Stats() (pending, running, completed, failed int) {
running++ running++
case JobStatusCompleted: case JobStatusCompleted:
completed++ completed++
case JobStatusFailed, JobStatusCancelled: case JobStatusFailed:
failed++ failed++
case JobStatusCancelled:
cancelled++
} }
} }
return return

View File

@ -443,6 +443,7 @@ type ConversionStatsBar struct {
pending int pending int
completed int completed int
failed int failed int
cancelled int
progress float64 progress float64
jobTitle string jobTitle string
fps float64 fps float64
@ -461,22 +462,24 @@ func NewConversionStatsBar(onTapped func()) *ConversionStatsBar {
} }
// UpdateStats updates the stats display // UpdateStats updates the stats display
func (c *ConversionStatsBar) UpdateStats(running, pending, completed, failed int, progress float64, jobTitle string) { func (c *ConversionStatsBar) UpdateStats(running, pending, completed, failed, cancelled int, progress float64, jobTitle string) {
c.running = running c.running = running
c.pending = pending c.pending = pending
c.completed = completed c.completed = completed
c.failed = failed c.failed = failed
c.cancelled = cancelled
c.progress = progress c.progress = progress
c.jobTitle = jobTitle c.jobTitle = jobTitle
c.Refresh() c.Refresh()
} }
// UpdateStatsWithDetails updates the stats display with detailed conversion info // UpdateStatsWithDetails updates the stats display with detailed conversion info
func (c *ConversionStatsBar) UpdateStatsWithDetails(running, pending, completed, failed int, progress, fps, speed float64, eta, jobTitle string) { func (c *ConversionStatsBar) UpdateStatsWithDetails(running, pending, completed, failed, cancelled int, progress, fps, speed float64, eta, jobTitle string) {
c.running = running c.running = running
c.pending = pending c.pending = pending
c.completed = completed c.completed = completed
c.failed = failed c.failed = failed
c.cancelled = cancelled
c.progress = progress c.progress = progress
c.fps = fps c.fps = fps
c.speed = speed c.speed = speed
@ -600,7 +603,7 @@ func (r *conversionStatsRenderer) Refresh() {
r.statusText.Text = "⏸ " + formatCount(r.bar.pending, "queued") r.statusText.Text = "⏸ " + formatCount(r.bar.pending, "queued")
r.statusText.Color = color.NRGBA{R: 255, G: 200, B: 100, A: 255} // Yellow r.statusText.Color = color.NRGBA{R: 255, G: 200, B: 100, A: 255} // Yellow
r.progressBar.Hide() r.progressBar.Hide()
} else if r.bar.completed > 0 || r.bar.failed > 0 { } else if r.bar.completed > 0 || r.bar.failed > 0 || r.bar.cancelled > 0 {
statusStr := "✓ " statusStr := "✓ "
parts := []string{} parts := []string{}
if r.bar.completed > 0 { if r.bar.completed > 0 {
@ -609,6 +612,9 @@ func (r *conversionStatsRenderer) Refresh() {
if r.bar.failed > 0 { if r.bar.failed > 0 {
parts = append(parts, formatCount(r.bar.failed, "failed")) parts = append(parts, formatCount(r.bar.failed, "failed"))
} }
if r.bar.cancelled > 0 {
parts = append(parts, formatCount(r.bar.cancelled, "cancelled"))
}
statusStr += strings.Join(parts, " • ") statusStr += strings.Join(parts, " • ")
r.statusText.Text = statusStr r.statusText.Text = statusStr
r.statusText.Color = color.NRGBA{R: 150, G: 150, B: 150, A: 255} // Gray r.statusText.Color = color.NRGBA{R: 150, G: 150, B: 150, A: 255} // Gray

View File

@ -751,7 +751,7 @@ func (s *appState) updateStatsBar() {
return return
} }
pending, running, completed, failed := s.jobQueue.Stats() pending, running, completed, failed, cancelled := s.jobQueue.Stats()
// Find the currently running job to get its progress and stats // Find the currently running job to get its progress and stats
var progress, fps, speed float64 var progress, fps, speed float64
@ -794,14 +794,14 @@ func (s *appState) updateStatsBar() {
} }
} }
s.statsBar.UpdateStatsWithDetails(running, pending, completed, failed, progress, fps, speed, eta, jobTitle) s.statsBar.UpdateStatsWithDetails(running, pending, completed, failed, cancelled, progress, fps, speed, eta, jobTitle)
} }
func (s *appState) queueProgressCounts() (completed, total int) { func (s *appState) queueProgressCounts() (completed, total int) {
if s.jobQueue == nil { if s.jobQueue == nil {
return 0, 0 return 0, 0
} }
pending, running, completedCount, failed := s.jobQueue.Stats() pending, running, completedCount, failed, cancelled := s.jobQueue.Stats()
// Total includes all jobs in memory, including cancelled/failed/pending // Total includes all jobs in memory, including cancelled/failed/pending
total = len(s.jobQueue.List()) total = len(s.jobQueue.List())
// Include direct conversion as an in-flight item in totals // Include direct conversion as an in-flight item in totals
@ -812,6 +812,7 @@ func (s *appState) queueProgressCounts() (completed, total int) {
_ = pending _ = pending
_ = running _ = running
_ = failed _ = failed
_ = cancelled
return return
} }
@ -1122,7 +1123,7 @@ func (s *appState) showMainMenu() {
// Get queue stats - show completed jobs out of total // Get queue stats - show completed jobs out of total
var queueCompleted, queueTotal int var queueCompleted, queueTotal int
if s.jobQueue != nil { if s.jobQueue != nil {
_, _, completed, _ := s.jobQueue.Stats() _, _, completed, _, _ := s.jobQueue.Stats()
queueCompleted = completed queueCompleted = completed
queueTotal = len(s.jobQueue.List()) queueTotal = len(s.jobQueue.List())
} }