mirror of
https://github.com/HDT3213/delayqueue.git
synced 2025-10-05 15:16:57 +08:00
@@ -120,6 +120,14 @@ func WithRetryCount(count int) interface{} {
|
||||
return retryCountOpt(count)
|
||||
}
|
||||
|
||||
type msgTTLOpt time.Duration
|
||||
|
||||
// WithMsgTTL set ttl for a msg
|
||||
// example: queue.SendDelayMsg(payload, duration, delayqueue.WithMsgTTL(Hour))
|
||||
func WithMsgTTL(d time.Duration) interface{} {
|
||||
return msgTTLOpt(d)
|
||||
}
|
||||
|
||||
// SendScheduleMsg submits a message delivered at given time
|
||||
func (q *DelayQueue) SendScheduleMsg(payload string, t time.Time, opts ...interface{}) error {
|
||||
// parse options
|
||||
@@ -128,6 +136,8 @@ func (q *DelayQueue) SendScheduleMsg(payload string, t time.Time, opts ...interf
|
||||
switch o := opt.(type) {
|
||||
case retryCountOpt:
|
||||
retryCount = uint(o)
|
||||
case msgTTLOpt:
|
||||
q.msgTTL = time.Duration(o)
|
||||
}
|
||||
}
|
||||
// generate id
|
||||
|
@@ -31,7 +31,7 @@ func TestDelayQueue_consume(t *testing.T) {
|
||||
WithFetchLimit(1)
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
err := queue.SendDelayMsg(strconv.Itoa(i), 0, WithRetryCount(retryCount))
|
||||
err := queue.SendDelayMsg(strconv.Itoa(i), 0, WithRetryCount(retryCount),WithMsgTTL(time.Hour))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func TestDelayQueue_ConcurrentConsume(t *testing.T) {
|
||||
WithConcurrent(4)
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
err := queue.SendDelayMsg(strconv.Itoa(i), 0, WithRetryCount(retryCount))
|
||||
err := queue.SendDelayMsg(strconv.Itoa(i), 0, WithRetryCount(retryCount),WithMsgTTL(time.Hour))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user