-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
145 lines (127 loc) · 3.29 KB
/
options.go
File metadata and controls
145 lines (127 loc) · 3.29 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package relay
import (
"time"
log "github.com/xraph/go-utils/log"
"github.com/xraph/relay/catalog"
"github.com/xraph/relay/delivery"
"github.com/xraph/relay/dlq"
"github.com/xraph/relay/endpoint"
"github.com/xraph/relay/observability"
"github.com/xraph/relay/store"
)
// Relay is the root webhook delivery engine.
type Relay struct {
config Config
store store.Store
catalog *catalog.Catalog
validator *catalog.Validator
endpointSvc *endpoint.Service
engine *delivery.Engine
dlqSvc *dlq.Service
logger log.Logger
metrics *observability.Metrics
tracer *observability.Tracer
}
// Option configures a Relay instance.
type Option func(*Relay) error
// New creates a new Relay with the given options.
func New(opts ...Option) (*Relay, error) {
r := &Relay{
config: DefaultConfig(),
logger: log.NewNoopLogger(),
}
for _, opt := range opts {
if err := opt(r); err != nil {
return nil, err
}
}
if r.store == nil {
return nil, ErrNoStore
}
r.wireServices()
return r, nil
}
// WithStore sets the persistence backend for the Relay instance.
func WithStore(s store.Store) Option {
return func(r *Relay) error {
r.store = s
return nil
}
}
// WithLogger sets the structured logger for the Relay instance.
func WithLogger(logger log.Logger) Option {
return func(r *Relay) error {
r.logger = logger
return nil
}
}
// WithConcurrency sets the number of delivery worker goroutines.
func WithConcurrency(n int) Option {
return func(r *Relay) error {
r.config.Concurrency = n
return nil
}
}
// WithPollInterval sets how often the delivery engine checks for pending deliveries.
func WithPollInterval(d time.Duration) Option {
return func(r *Relay) error {
r.config.PollInterval = d
return nil
}
}
// WithBatchSize sets the maximum number of deliveries dequeued per poll cycle.
func WithBatchSize(n int) Option {
return func(r *Relay) error {
r.config.BatchSize = n
return nil
}
}
// WithRequestTimeout sets the HTTP timeout per delivery attempt.
func WithRequestTimeout(d time.Duration) Option {
return func(r *Relay) error {
r.config.RequestTimeout = d
return nil
}
}
// WithMaxRetries sets the global default for maximum delivery attempts.
func WithMaxRetries(n int) Option {
return func(r *Relay) error {
r.config.MaxRetries = n
return nil
}
}
// WithRetrySchedule sets the backoff intervals between retry attempts.
func WithRetrySchedule(schedule []time.Duration) Option {
return func(r *Relay) error {
r.config.RetrySchedule = schedule
return nil
}
}
// WithShutdownTimeout sets the maximum time to wait for in-flight deliveries on shutdown.
func WithShutdownTimeout(d time.Duration) Option {
return func(r *Relay) error {
r.config.ShutdownTimeout = d
return nil
}
}
// WithCacheTTL sets the TTL for the catalog's in-memory event type cache.
func WithCacheTTL(d time.Duration) Option {
return func(r *Relay) error {
r.config.CacheTTL = d
return nil
}
}
// WithMetrics sets the Prometheus metrics recorder for the Relay instance.
func WithMetrics(m *observability.Metrics) Option {
return func(r *Relay) error {
r.metrics = m
return nil
}
}
// WithTracer sets the OpenTelemetry tracer for the Relay instance.
func WithTracer(t *observability.Tracer) Option {
return func(r *Relay) error {
r.tracer = t
return nil
}
}