Skip to content

Commit

Permalink
refactor: refactor metric handling by removing IncCompletedTask method
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
appleboy committed Jan 25, 2025
1 parent 15d348a commit 013bf95
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
8 changes: 1 addition & 7 deletions metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Metric interface {
IncSuccessTask()
IncFailureTask()
IncSubmittedTask()
IncCompletedTask()
}

var _ Metric = (*metric)(nil)
Expand All @@ -24,7 +23,6 @@ type metric struct {
successTasks uint64
failureTasks uint64
submittedTasks uint64
completedTasks uint64
}

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

func (m *metric) IncCompletedTask() {
atomic.AddUint64(&m.completedTasks, 1)
}

func (m *metric) SuccessTasks() uint64 {
return atomic.LoadUint64(&m.successTasks)
}
Expand All @@ -73,5 +67,5 @@ func (m *metric) SubmittedTasks() uint64 {
}

func (m *metric) CompletedTasks() uint64 {
return atomic.LoadUint64(&m.completedTasks)
return atomic.LoadUint64(&m.successTasks) + atomic.LoadUint64(&m.failureTasks)
}
1 change: 0 additions & 1 deletion queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (q *Queue) work(task core.TaskMessage) {
if q.afterFn != nil {
q.afterFn()
}
q.metric.IncCompletedTask()
}()

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

0 comments on commit 013bf95

Please sign in to comment.