Skip to content

Commit fec222d

Browse files
committed
Move Timer to internal package
1 parent c701de3 commit fec222d

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

metrics/timer.go renamed to internal/metrics/timer.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package metrics
22

33
import (
44
"time"
5+
6+
"github.com/cschleiden/go-workflows/metrics"
57
)
68

7-
type timer struct {
8-
client Client
9+
type Timer struct {
10+
client metrics.Client
911
start time.Time
1012
name string
11-
tags Tags
13+
tags metrics.Tags
1214
}
1315

14-
func Timer(client Client, name string, tags Tags) *timer {
15-
return &timer{
16+
func NewTimer(client metrics.Client, name string, tags metrics.Tags) *Timer {
17+
return &Timer{
1618
client: client,
1719
start: time.Now(),
1820
name: name,
@@ -21,7 +23,7 @@ func Timer(client Client, name string, tags Tags) *timer {
2123
}
2224

2325
// Stop the timer and send the elapsed time as milliseconds as a distribution metric
24-
func (t *timer) Stop() {
26+
func (t *Timer) Stop() {
2527
elapsed := time.Since(t.start)
2628
t.client.Distribution(t.name, t.tags, float64(elapsed/time.Millisecond))
2729
}

internal/worker/activity.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cschleiden/go-workflows/backend/payload"
1414
"github.com/cschleiden/go-workflows/internal/activity"
1515
"github.com/cschleiden/go-workflows/internal/metrickeys"
16+
mi "github.com/cschleiden/go-workflows/internal/metrics"
1617
"github.com/cschleiden/go-workflows/internal/workflow"
1718
"github.com/cschleiden/go-workflows/internal/workflowerrors"
1819
"github.com/cschleiden/go-workflows/metrics"
@@ -153,7 +154,7 @@ func (aw *ActivityWorker) handleTask(ctx context.Context, task *backend.Activity
153154
}(heartbeatCtx)
154155
}
155156

156-
timer := metrics.Timer(ametrics, metrickeys.ActivityTaskProcessed, metrics.Tags{})
157+
timer := mi.NewTimer(ametrics, metrickeys.ActivityTaskProcessed, metrics.Tags{})
157158
defer timer.Stop()
158159

159160
result, err := aw.activityTaskExecutor.ExecuteActivity(ctx, task)

internal/worker/workflow.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cschleiden/go-workflows/backend/history"
1414
"github.com/cschleiden/go-workflows/core"
1515
"github.com/cschleiden/go-workflows/internal/metrickeys"
16+
mi "github.com/cschleiden/go-workflows/internal/metrics"
1617
"github.com/cschleiden/go-workflows/internal/workflow"
1718
"github.com/cschleiden/go-workflows/internal/workflow/cache"
1819
"github.com/cschleiden/go-workflows/metrics"
@@ -150,7 +151,7 @@ func (ww *WorkflowWorker) handle(ctx context.Context, t *backend.WorkflowTask) {
150151
metrickeys.EventName: eventName,
151152
}, float64(timeInQueue/time.Millisecond))
152153

153-
timer := metrics.Timer(ww.backend.Metrics(), metrickeys.WorkflowTaskProcessed, metrics.Tags{
154+
timer := mi.NewTimer(ww.backend.Metrics(), metrickeys.WorkflowTaskProcessed, metrics.Tags{
154155
metrickeys.EventName: eventName,
155156
})
156157

0 commit comments

Comments
 (0)