File tree Expand file tree Collapse file tree 2 files changed +0
-44
lines changed Expand file tree Collapse file tree 2 files changed +0
-44
lines changed Original file line number Diff line number Diff line change @@ -21,20 +21,6 @@ type Consumer struct {
2121 logger Logger
2222 stopOnce sync.Once
2323 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 ()
3824}
3925
4026func (s * Consumer ) handle (job Job ) error {
@@ -43,10 +29,8 @@ func (s *Consumer) handle(job Job) error {
4329 panicChan := make (chan interface {}, 1 )
4430 startTime := time .Now ()
4531 ctx , cancel := context .WithTimeout (context .Background (), job .Timeout )
46- s .incBusyWorker ()
4732 defer func () {
4833 cancel ()
49- s .decBusyWorker ()
5034 }()
5135
5236 // run the job
@@ -157,7 +141,6 @@ func NewConsumer(opts ...Option) *Consumer {
157141 stop : make (chan struct {}),
158142 logger : o .logger ,
159143 runFunc : o .fn ,
160- metric : o .metric ,
161144 }
162145
163146 return w
Original file line number Diff line number Diff line change @@ -321,30 +321,3 @@ func TestTaskJobComplete(t *testing.T) {
321321 }
322322 assert .Equal (t , context .DeadlineExceeded , w .handle (job ))
323323}
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