-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
77 lines (70 loc) · 2.06 KB
/
config.go
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
package dlqdump
import (
"time"
"github.com/koykov/queue"
)
const (
// Default time limit to flush the data.
defaultFlushInterval = time.Second * 30
// Default rate limit that allows restore.
defaultAllowRate = .95
// Default delay if restore allow rate limit exceeds.
defaultCheckInterval = time.Second
)
type Config struct {
/*
Common params.
*/
// Write version. Must be changed at any change of Encoder param.
Version Version
// Metrics writer handler.
MetricsWriter MetricsWriter
// Logger handler.
Logger queue.Logger
/*
Queue params.
Params of this group will ignore by Restorer.
*/
// Max queue capacity in bytes.
// When dumped data will reach size, queue will flush the data.
// Mandatory param.
Capacity MemorySize
// Wait duration until flush the data.
// After first incoming item will start the timer to flush the data when timer reach.
// If this param omit defaultFlushInterval (30 seconds) will use by default.
FlushInterval time.Duration
// Encoder helper to convert item to bytes.
// Mandatory param.
Encoder Encoder
// Writer helper to dump data to various destinations.
// Mandatory param.
Writer Writer
/*
Restorer params.
Params of this group will ignore by Queue.
*/
// Interval between restore attempts.
// If this param omit defaultWaitInterval (1 second) will use by default.
CheckInterval time.Duration
// Wait duration if queue rate exceeds AllowRate.
// If this param omit CheckInterval will use instead.
PostponeInterval time.Duration
// Queue rate that allows restore.
// If this param omit defaultAllowRate (95%) will use by default.
AllowRate float32
// Helper to achieve data from dump.
// Mandatory param.
Reader Reader
// Decoder helper to convert bytes to item.
// Mandatory param.
Decoder Decoder
// Destination queue to restore dump.
// Mandatory param.
Queue queue.Interface
}
// Copy copies config instance to protect queue from changing params after start.
// It means that after starting queue all config modifications will have no effect.
func (c *Config) Copy() *Config {
cpy := *c
return &cpy
}