1
1
package redisconsistent
2
2
3
3
import (
4
+ "fmt"
4
5
"time"
5
6
6
7
"github.com/google/uuid"
7
8
"github.com/redis/go-redis/v9"
8
9
9
10
"github.com/streemtech/divider"
11
+ "github.com/streemtech/divider/internal/redisstreams"
10
12
"github.com/streemtech/divider/internal/set"
11
13
)
12
14
@@ -20,13 +22,9 @@ type dividerConf struct {
20
22
starter StarterFunc
21
23
stopper StarterFunc
22
24
23
- //how often the master updates itself
24
- masterPing time.Duration
25
25
//how long the master reserves itself.
26
26
masterTimeout time.Duration
27
27
28
- //how long the workers wait between pings in the storage
29
- workerPing time.Duration
30
28
//how long the workers wait before counting a timeout.
31
29
workerTimeout time.Duration
32
30
@@ -95,27 +93,13 @@ func WithMasterTimeoutDuration(value time.Duration) DividerOpt {
95
93
}
96
94
}
97
95
98
- // Time that masters will wait between updating their "im alive" statuses.
99
- func WithMasterPingTime (value time.Duration ) DividerOpt {
100
- return func (dc * dividerConf ) {
101
- dc .masterPing = value
102
- }
103
- }
104
-
105
96
// Time that a worker can be in the list after a ping and have not reported.
106
97
func WithWorkerTimeoutDuration (value time.Duration ) DividerOpt {
107
98
return func (dc * dividerConf ) {
108
99
dc .workerTimeout = value
109
100
}
110
101
}
111
102
112
- // Time that workers will wait between updating their "im alive" statuses.
113
- func WithWorkerPingTime (value time.Duration ) DividerOpt {
114
- return func (dc * dividerConf ) {
115
- dc .workerPing = value
116
- }
117
- }
118
-
119
103
// time between checking for the full list of work.
120
104
func WithUpdateAssignmentsDuration (value time.Duration ) DividerOpt {
121
105
return func (dc * dividerConf ) {
@@ -138,9 +122,7 @@ func New(client redis.UniversalClient, rootKey string, Opts ...DividerOpt) (divi
138
122
nodeCount : 10 ,
139
123
logger : divider .DefaultLogger ,
140
124
masterTimeout : time .Second * 10 ,
141
- masterPing : time .Second ,
142
125
workerTimeout : time .Second * 10 ,
143
- workerPing : time .Second ,
144
126
145
127
updateAssignments : time .Second * 10 ,
146
128
compareKeys : time .Second * 10 ,
@@ -161,5 +143,34 @@ func New(client redis.UniversalClient, rootKey string, Opts ...DividerOpt) (divi
161
143
workerTimeout : conf .workerTimeout ,
162
144
rootKey : conf .rootKey ,
163
145
},
146
+ //start tickers and listeners
147
+ newWorker : redisstreams.StreamListener {
148
+ // Ctx: ctx,
149
+ Client : client ,
150
+ Key : fmt .Sprintf ("%s:%s" , conf .rootKey , "new_worker" ),
151
+ // Callback: d.newWorkerEvent,
152
+ Logger : conf .logger ,
153
+ },
154
+ removeWorker : redisstreams.StreamListener {
155
+ // Ctx: ctx,
156
+ Client : client ,
157
+ Key : fmt .Sprintf ("%s:%s" , conf .rootKey , "remove_worker" ),
158
+ // Callback: d.removeWorkerEvent,
159
+ Logger : conf .logger ,
160
+ },
161
+ newWork : redisstreams.StreamListener {
162
+ // Ctx: ctx,
163
+ Client : client ,
164
+ Key : fmt .Sprintf ("%s:%s" , conf .rootKey , "new_work" ),
165
+ // Callback: d.newWorkEvent,
166
+ Logger : conf .logger ,
167
+ },
168
+ removeWork : redisstreams.StreamListener {
169
+ // Ctx: ctx,
170
+ Client : client ,
171
+ Key : fmt .Sprintf ("%s:%s" , conf .rootKey , "remove_work" ),
172
+ // Callback: d.removeWorkEvent,
173
+ Logger : conf .logger ,
174
+ },
164
175
}, nil
165
176
}
0 commit comments