-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
73 lines (61 loc) · 1.71 KB
/
options.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package taskrunner
import (
"errors"
"github.com/go-kit/kit/metrics"
)
// OptionMaxGoroutines is a functional option for configuring the number of
// workers in a TaskRunner.
func OptionMaxGoroutines(n int) Option {
return func(r *TaskRunner) error {
if n <= 0 {
return errors.New("number of goroutines must be positive")
}
r.maxWorkers = n
return nil
}
}
// OptionTaskCounter allows access to the a metrics.Counter which aggregates
// the number of tasks processed.
func OptionTaskCounter(ctr metrics.Counter) Option {
return func(r *TaskRunner) error {
if ctr == nil {
return errors.New("counter must be non-nil")
}
r.taskCounter = ctr
return nil
}
}
// OptionUnhandledPromisesGauge allows a go-kit metrics.Gauge to be passed-in
// collect the number of unhandled promises.
// Useful to discover if there is a leak of unhandled promises in-memory.
func OptionUnhandledPromisesGauge(gauge metrics.Gauge) Option {
return func(r *TaskRunner) error {
if gauge == nil {
return errors.New("gauge must be non-nil")
}
r.unhandledPromisesGauge = gauge
return nil
}
}
// OptionWorkersGauge allows access to the current number of workers via a
// go-kit metrics.Gauge.
func OptionWorkersGauge(gauge metrics.Gauge) Option {
return func(r *TaskRunner) error {
if gauge == nil {
return errors.New("gauge must be non-nil")
}
r.workersGauge = gauge
return nil
}
}
// OptionTaskTimeHistogram allows access to customize a histogram for sampling
// average task times.
func OptionTaskTimeHistogram(histogram metrics.Histogram) Option {
return func(r *TaskRunner) error {
if histogram == nil {
return errors.New("histogram must be non-nil")
}
r.averageTaskTime = histogram
return nil
}
}