@@ -95,18 +95,32 @@ func NewQ(name string, cfg Config) (*rtQ, error) {
95
95
statusError : cfg .Logger .Error ,
96
96
}
97
97
98
- go rtq .tx () // start transmitting
99
- //rtq.QStats(b) // start status monitoring
98
+ // start transmitting
99
+ go func () {
100
+ // endless loop
101
+ for {
102
+ rtq .tx ()
103
+ rtq .status ("TransmissionStatus" , zapcore.Field {
104
+ Key : "WaitSecond" ,
105
+ Type : zapcore .Int32Type ,
106
+ Integer : int64 (rtq .cfg .Interval / time .Second ),
107
+ })
108
+
109
+ // wait for interval to pass
110
+ <- time .After (rtq .cfg .Interval )
111
+ }
112
+
113
+ }()
100
114
101
115
return rtq , nil
102
116
}
103
117
104
118
// getMessageBatch starts at the first record and
105
119
// builds a MessageBatch for each found key up to the
106
120
// batch size.
107
- func (rt * rtQ ) getMessageBatch () MessageBatch {
121
+ func (rt * rtQ ) getMessageBatch () * MessageBatch {
108
122
uuidV4 , _ := uuid .NewV4 ()
109
- mb := MessageBatch {
123
+ mb := & MessageBatch {
110
124
Uuid : uuidV4 .String (),
111
125
}
112
126
@@ -172,7 +186,7 @@ func (rt *rtQ) getMessageBatch() MessageBatch {
172
186
}
173
187
174
188
// transmit attempts to transmit a message batch
175
- func (rt * rtQ ) transmit (msgB MessageBatch ) error {
189
+ func (rt * rtQ ) transmit (msgB * MessageBatch ) error {
176
190
177
191
jsonStr , err := json .Marshal (msgB )
178
192
if err != nil {
@@ -223,7 +237,6 @@ func (rt *rtQ) tx() {
223
237
if mb .Size < 1 {
224
238
// nothing to send
225
239
rt .status ("TransmissionSkipEmpty" )
226
- rt .waitTx ()
227
240
return
228
241
}
229
242
@@ -251,7 +264,6 @@ func (rt *rtQ) tx() {
251
264
if rt .mCount > rt .cfg .MaxInQueue {
252
265
rt .remove <- rt .mCount - rt .cfg .MaxInQueue
253
266
}
254
- rt .waitTx ()
255
267
return
256
268
}
257
269
@@ -264,19 +276,6 @@ func (rt *rtQ) tx() {
264
276
Integer : int64 (mb .Size ),
265
277
})
266
278
rt .remove <- mb .Size
267
- rt .waitTx ()
268
- }
269
-
270
- // waitTx sleeps for rt.cfg.Interval * time.Second then performs a tx.
271
- func (rt * rtQ ) waitTx () {
272
- rt .status ("TransmissionStatus" , zapcore.Field {
273
- Key : "WaitSecond" ,
274
- Type : zapcore .Int32Type ,
275
- Integer : int64 (rt .cfg .Interval / time .Second ),
276
- })
277
-
278
- time .Sleep (rt .cfg .Interval )
279
- rt .tx () // recursion
280
279
}
281
280
282
281
// Write to the queue
0 commit comments