Summary returns a human-readable summary of check progress. Example: "Completed: AccessURL (95ms), Database (120ms). Still running: DERP, Websocket"
()
| 70 | // Summary returns a human-readable summary of check progress. |
| 71 | // Example: "Completed: AccessURL (95ms), Database (120ms). Still running: DERP, Websocket" |
| 72 | func (p *Progress) Summary() string { |
| 73 | p.mu.Lock() |
| 74 | defer p.mu.Unlock() |
| 75 | |
| 76 | var completed, running []string |
| 77 | for name, status := range p.checks { |
| 78 | if status.completedAt.IsZero() { |
| 79 | elapsed := p.Clock.Now().Sub(status.startedAt).Round(time.Millisecond) |
| 80 | running = append(running, fmt.Sprintf("%s (elapsed: %dms)", name, elapsed.Milliseconds())) |
| 81 | continue |
| 82 | } |
| 83 | duration := status.completedAt.Sub(status.startedAt).Round(time.Millisecond) |
| 84 | completed = append(completed, fmt.Sprintf("%s (%dms)", name, duration.Milliseconds())) |
| 85 | } |
| 86 | |
| 87 | // Sort for consistent output. |
| 88 | slices.Sort(completed) |
| 89 | slices.Sort(running) |
| 90 | |
| 91 | var parts []string |
| 92 | if len(completed) > 0 { |
| 93 | parts = append(parts, "Completed: "+strings.Join(completed, ", ")) |
| 94 | } |
| 95 | if len(running) > 0 { |
| 96 | parts = append(parts, "Still running: "+strings.Join(running, ", ")) |
| 97 | } |
| 98 | return strings.Join(parts, ". ") |
| 99 | } |
| 100 | |
| 101 | type Checker interface { |
| 102 | DERP(ctx context.Context, opts *derphealth.ReportOptions) healthsdk.DERPHealthReport |