Get merge queue failure rate by day. Triggers backfill if needed.
(date_from: str, date_to: str)
| 635 | |
| 636 | |
| 637 | def get_merge_queue_stats(date_from: str, date_to: str) -> dict: |
| 638 | """Get merge queue failure rate by day. Triggers backfill if needed.""" |
| 639 | # Ensure data is populated (async after first load) |
| 640 | import db |
| 641 | conn = db.get_db() |
| 642 | count = conn.execute('SELECT COUNT(*) as c FROM merge_queue_daily').fetchone()['c'] |
| 643 | if count == 0: |
| 644 | ensure_merge_queue_data() # block on first load |
| 645 | else: |
| 646 | threading.Thread(target=ensure_merge_queue_data, daemon=True).start() |
| 647 | |
| 648 | rows = db.query( |
| 649 | 'SELECT date, total, success, failure, cancelled, in_progress ' |
| 650 | 'FROM merge_queue_daily WHERE date >= ? AND date <= ? ORDER BY date', |
| 651 | (date_from, date_to)) |
| 652 | |
| 653 | total_runs = sum(r['total'] for r in rows) |
| 654 | total_fail = sum(r['failure'] for r in rows) |
| 655 | total_success = sum(r['success'] for r in rows) |
| 656 | |
| 657 | return { |
| 658 | 'by_date': rows, |
| 659 | 'summary': { |
| 660 | 'total_runs': total_runs, |
| 661 | 'total_success': total_success, |
| 662 | 'total_failure': total_fail, |
| 663 | 'failure_rate': round(total_fail / max(total_runs, 1) * 100, 1), |
| 664 | 'days': len([r for r in rows if r['total'] > 0]), |
| 665 | }, |
| 666 | } |
nothing calls this directly
no test coverage detected