File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package redisdb
2
2
3
3
import (
4
4
"context"
5
+ "time"
5
6
6
7
"github.com/golang-queue/queue"
7
8
"github.com/golang-queue/queue/core"
@@ -22,6 +23,7 @@ type options struct {
22
23
group string
23
24
consumer string
24
25
maxLength int64
26
+ blockTime time.Duration
25
27
}
26
28
27
29
// WithAddr setup the addr of redis
@@ -38,6 +40,15 @@ func WithMaxLength(m int64) Option {
38
40
}
39
41
}
40
42
43
+ // WithBlockTime setup the block time for publish messages
44
+ // we use the block command to make sure if no entry is found we wait
45
+ // until an entry is found
46
+ func WithBlockTime (m time.Duration ) Option {
47
+ return func (w * options ) {
48
+ w .blockTime = m
49
+ }
50
+ }
51
+
41
52
// WithPassword redis password
42
53
func WithDB (db int ) Option {
43
54
return func (w * options ) {
@@ -111,6 +122,7 @@ func newOptions(opts ...Option) options {
111
122
runFunc : func (context.Context , core.QueuedMessage ) error {
112
123
return nil
113
124
},
125
+ blockTime : 60 * time .Second ,
114
126
}
115
127
116
128
// Loop through each option
Original file line number Diff line number Diff line change @@ -16,8 +16,6 @@ import (
16
16
17
17
var _ core.Worker = (* Worker )(nil )
18
18
19
- const blockTime = 60000
20
-
21
19
// Worker for Redis
22
20
type Worker struct {
23
21
// redis config
@@ -103,10 +101,10 @@ func (w *Worker) fetchTask() {
103
101
Count : 1 ,
104
102
// we use the block command to make sure if no entry is found we wait
105
103
// until an entry is found
106
- Block : blockTime ,
104
+ Block : w . opts . blockTime ,
107
105
}).Result ()
108
106
if err != nil {
109
- w .opts .logger .Errorf ("error while reading from redis %v" ,err )
107
+ w .opts .logger .Errorf ("error while reading from redis %v" , err )
110
108
continue
111
109
}
112
110
// we have received the data we should loop it and queue the messages
You can’t perform that action at this time.
0 commit comments