-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmetrics.go
46 lines (37 loc) · 999 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package async_account
import (
"context"
"time"
"github.com/code-payments/code-server/pkg/metrics"
)
const (
giftCardWorkerEventName = "GiftCardWorkerPollingCheck"
swapRetryWorkerEventName = "SwapRetryWorkerPollingCheck"
)
func (p *service) metricsGaugeWorker(ctx context.Context) error {
delay := time.Second
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(delay):
start := time.Now()
p.recordBackupQueueStatusPollingEvent(ctx)
delay = time.Second - time.Since(start)
}
}
}
func (p *service) recordBackupQueueStatusPollingEvent(ctx context.Context) {
count, err := p.data.GetAccountInfoCountRequiringAutoReturnCheck(ctx)
if err == nil {
metrics.RecordEvent(ctx, giftCardWorkerEventName, map[string]interface{}{
"queue_size": count,
})
}
count, err = p.data.GetAccountInfoCountRequiringSwapRetry(ctx)
if err == nil {
metrics.RecordEvent(ctx, swapRetryWorkerEventName, map[string]interface{}{
"queue_size": count,
})
}
}