| 503 | } |
| 504 | |
| 505 | func (q *SQLiteQueue) Stats(tenantId int64, queueName string) models.QueueStats { |
| 506 | queue, err := q.getQueue(tenantId, queueName) |
| 507 | if err != nil { |
| 508 | return models.QueueStats{} |
| 509 | } |
| 510 | |
| 511 | now := time.Now().UTC().Unix() |
| 512 | |
| 513 | res := q.DBG.Raw(` |
| 514 | SELECT |
| 515 | CASE |
| 516 | WHEN tries = max_tries AND deliver_at < ? THEN 3 |
| 517 | WHEN delivered_at <= ? AND deliver_at > ? THEN 2 |
| 518 | ELSE 1 |
| 519 | END AS s, |
| 520 | count(*) FROM messages WHERE queue_id=? AND tenant_id=? GROUP BY s |
| 521 | `, now, now, now, |
| 522 | queue.ID, tenantId, |
| 523 | ) |
| 524 | |
| 525 | if res.Error != nil { |
| 526 | return models.QueueStats{} |
| 527 | } |
| 528 | |
| 529 | rows, err := res.Rows() |
| 530 | if err != nil { |
| 531 | return models.QueueStats{} |
| 532 | } |
| 533 | |
| 534 | stats := models.QueueStats{ |
| 535 | Counts: make(map[models.MessageStatus]int), |
| 536 | TotalMessages: 0, |
| 537 | } |
| 538 | |
| 539 | for rows.Next() { |
| 540 | var statusType models.MessageStatus |
| 541 | var count int |
| 542 | |
| 543 | rows.Scan(&statusType, &count) |
| 544 | |
| 545 | stats.TotalMessages += count |
| 546 | stats.Counts[statusType] = count |
| 547 | } |
| 548 | |
| 549 | rows.Close() |
| 550 | |
| 551 | return stats |
| 552 | } |
| 553 | |
| 554 | func (q *SQLiteQueue) Filter(tenantId int64, queueName string, filterCriteria models.FilterCriteria) []int64 { |
| 555 | var rc []int64 |