-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.go
More file actions
45 lines (34 loc) · 1.44 KB
/
Copy pathhooks.go
File metadata and controls
45 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package kata
import (
"context"
"time"
)
// Hooks provides lifecycle callbacks for observability (logging, metrics, tracing).
type Hooks struct {
// OnStepStart is called before each step begins executing.
OnStepStart func(ctx context.Context, name string)
// OnStepDone is called after a step completes successfully.
OnStepDone func(ctx context.Context, name string, duration time.Duration)
// OnStepFailed is called when a step fails (after all retries are exhausted).
OnStepFailed func(ctx context.Context, name string, err error)
// OnRetry is called before each retry attempt.
// attempt starts at 1 (first retry), err is the error from the previous attempt.
OnRetry func(ctx context.Context, name string, attempt int, err error)
// OnCompensationStart is called before a compensation function begins.
OnCompensationStart func(ctx context.Context, name string)
// OnCompensationDone is called after a compensation completes successfully.
OnCompensationDone func(ctx context.Context, name string)
// OnCompensationFailed is called when a compensation function fails.
OnCompensationFailed func(ctx context.Context, name string, err error)
}
// WithHooks is an option to set observability hooks on a Runner.
func WithHooks(h Hooks) RunnerOption {
return func(cfg *runnerConfig) {
cfg.hooks = h
}
}
// RunnerOption is a functional option for configuring a Runner.
type RunnerOption func(*runnerConfig)
type runnerConfig struct {
hooks Hooks
}