diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9f61a3e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: go + +go: + - 1.16.x +before_install: + - sudo apt-get install redis-server; redis-server & + - go install github.com/mattn/goveralls@latest +script: + - $GOPATH/bin/goveralls -service=travis-ci diff --git a/README.md b/README.md index 3d6d997..dd38d3d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # DelayQueue +![license](https://img.shields.io/github/license/HDT3213/delayqueue) +[![Build Status](https://travis-ci.com/HDT3213/delayqueue.svg?branch=master)](https://app.travis-ci.com/github/HDT3213/delayqueue) +[![Coverage Status](https://coveralls.io/repos/github/HDT3213/delayqueue/badge.svg?branch=master)](https://coveralls.io/github/HDT3213/delayqueue?branch=master) +[![Go Report Card](https://goreportcard.com/badge/github.com/HDT3213/delayqueue)](https://goreportcard.com/report/github.com/HDT3213/delayqueue) +[![Go Reference](https://pkg.go.dev/badge/github.com/hdt3213/delayqueue.svg)](https://pkg.go.dev/github.com/hdt3213/delayqueue) + DelayQueue is a message queue supporting delayed/scheduled delivery based on redis. DelayQueue guarantees to deliver at least once. @@ -76,3 +82,12 @@ WithFetchLimit(limit uint) ``` WithFetchLimit limits the max number of messages at one time + + +``` +WithDefaultRetryCount(count uint) +``` + +WithDefaultRetryCount customizes the max number of retry, it effects of messages in this queue + +use WithRetryCount during DelayQueue.SendScheduleMsg or DelayQueue.SendDelayMsg to specific retry count of particular message \ No newline at end of file diff --git a/delayqueue.go b/delayqueue.go index c9cd161..2d56893 100644 --- a/delayqueue.go +++ b/delayqueue.go @@ -29,7 +29,7 @@ type DelayQueue struct { maxConsumeDuration time.Duration msgTTL time.Duration - defaultRetryCount int + defaultRetryCount uint fetchInterval time.Duration fetchLimit uint } @@ -92,6 +92,13 @@ func (q *DelayQueue) WithFetchLimit(limit uint) *DelayQueue { return q } +// WithDefaultRetryCount customizes the max number of retry, it effects of messages in this queue +// use WithRetryCount during DelayQueue.SendScheduleMsg or DelayQueue.SendDelayMsg to specific retry count of particular message +func (q *DelayQueue) WithDefaultRetryCount(count uint) *DelayQueue { + q.defaultRetryCount = count + return q +} + func (q *DelayQueue) genMsgKey(idStr string) string { return "dp:" + q.name + ":msg:" + idStr } @@ -127,7 +134,7 @@ func (q *DelayQueue) SendScheduleMsg(payload string, t time.Time, opts ...interf for _, opt := range opts { switch o := opt.(type) { case retryCountOpt: - retryCount = int(o) + retryCount = uint(o) } } // generate id diff --git a/delayqueue_test.go b/delayqueue_test.go index 715cc77..dcf66b1 100644 --- a/delayqueue_test.go +++ b/delayqueue_test.go @@ -71,7 +71,7 @@ func TestDelayQueue_StopConsume(t *testing.T) { queue.StopConsume() } return true - }) + }).WithDefaultRetryCount(1) for i := 0; i < size; i++ { err := queue.SendDelayMsg(strconv.Itoa(i), 0) if err != nil { @@ -102,7 +102,3 @@ func TestIDOverflow(t *testing.T) { } } } - -func TestDelayQUeu(t *testing.T) { - -}