File tree 2 files changed +0
-44
lines changed
2 files changed +0
-44
lines changed Original file line number Diff line number Diff line change @@ -21,20 +21,6 @@ type Consumer struct {
21
21
logger Logger
22
22
stopOnce sync.Once
23
23
stopFlag int32
24
- metric Metric
25
- }
26
-
27
- func (s * Consumer ) incBusyWorker () {
28
- s .metric .IncBusyWorker ()
29
- }
30
-
31
- func (s * Consumer ) decBusyWorker () {
32
- s .metric .DecBusyWorker ()
33
- }
34
-
35
- // BusyWorkers returns the numbers of workers has been busy.
36
- func (s * Consumer ) BusyWorkers () uint64 {
37
- return s .metric .BusyWorkers ()
38
24
}
39
25
40
26
func (s * Consumer ) handle (job Job ) error {
@@ -43,10 +29,8 @@ func (s *Consumer) handle(job Job) error {
43
29
panicChan := make (chan interface {}, 1 )
44
30
startTime := time .Now ()
45
31
ctx , cancel := context .WithTimeout (context .Background (), job .Timeout )
46
- s .incBusyWorker ()
47
32
defer func () {
48
33
cancel ()
49
- s .decBusyWorker ()
50
34
}()
51
35
52
36
// run the job
@@ -157,7 +141,6 @@ func NewConsumer(opts ...Option) *Consumer {
157
141
stop : make (chan struct {}),
158
142
logger : o .logger ,
159
143
runFunc : o .fn ,
160
- metric : o .metric ,
161
144
}
162
145
163
146
return w
Original file line number Diff line number Diff line change @@ -321,30 +321,3 @@ func TestTaskJobComplete(t *testing.T) {
321
321
}
322
322
assert .Equal (t , context .DeadlineExceeded , w .handle (job ))
323
323
}
324
-
325
- func TestBusyWorkerCount (t * testing.T ) {
326
- job := Job {
327
- Timeout : 200 * time .Millisecond ,
328
- Task : func (ctx context.Context ) error {
329
- time .Sleep (100 * time .Millisecond )
330
- return nil
331
- },
332
- }
333
-
334
- w := NewConsumer ()
335
-
336
- assert .Equal (t , uint64 (0 ), w .BusyWorkers ())
337
- go func () {
338
- assert .NoError (t , w .handle (job ))
339
- }()
340
- go func () {
341
- assert .NoError (t , w .handle (job ))
342
- }()
343
-
344
- time .Sleep (50 * time .Millisecond )
345
- assert .Equal (t , uint64 (2 ), w .BusyWorkers ())
346
- time .Sleep (100 * time .Millisecond )
347
- assert .Equal (t , uint64 (0 ), w .BusyWorkers ())
348
-
349
- assert .NoError (t , w .Shutdown ())
350
- }
You can’t perform that action at this time.
0 commit comments