Skip to content

Commit 76cd814

Browse files
authored
refactor: refactor metric handling by removing IncCompletedTask method (#140)
- Remove `IncCompletedTask` method from `Metric` interface - Remove `completedTasks` field from `metric` struct - Remove `IncCompletedTask` method implementation - Update `CompletedTasks` method to return the sum of `successTasks` and `failureTasks` - Remove call to `IncCompletedTask` in `Queue`'s `work` method Signed-off-by: appleboy <[email protected]>
1 parent 15d348a commit 76cd814

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

metric.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type Metric interface {
1414
IncSuccessTask()
1515
IncFailureTask()
1616
IncSubmittedTask()
17-
IncCompletedTask()
1817
}
1918

2019
var _ Metric = (*metric)(nil)
@@ -24,7 +23,6 @@ type metric struct {
2423
successTasks uint64
2524
failureTasks uint64
2625
submittedTasks uint64
27-
completedTasks uint64
2826
}
2927

3028
// NewMetric for default metric structure
@@ -56,10 +54,6 @@ func (m *metric) IncSubmittedTask() {
5654
atomic.AddUint64(&m.submittedTasks, 1)
5755
}
5856

59-
func (m *metric) IncCompletedTask() {
60-
atomic.AddUint64(&m.completedTasks, 1)
61-
}
62-
6357
func (m *metric) SuccessTasks() uint64 {
6458
return atomic.LoadUint64(&m.successTasks)
6559
}
@@ -73,5 +67,5 @@ func (m *metric) SubmittedTasks() uint64 {
7367
}
7468

7569
func (m *metric) CompletedTasks() uint64 {
76-
return atomic.LoadUint64(&m.completedTasks)
70+
return atomic.LoadUint64(&m.successTasks) + atomic.LoadUint64(&m.failureTasks)
7771
}

queue.go

-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func (q *Queue) work(task core.TaskMessage) {
172172
if q.afterFn != nil {
173173
q.afterFn()
174174
}
175-
q.metric.IncCompletedTask()
176175
}()
177176

178177
if err = q.run(task); err != nil {

0 commit comments

Comments
 (0)