From f5b7e0cccdec53ebb1d2aa400e45bdecd411850a Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Sat, 21 Dec 2019 10:02:03 -0800 Subject: [PATCH] Document options precedence --- client.go | 3 +++ client_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/client.go b/client.go index 96ef557..cb12b1f 100644 --- a/client.go +++ b/client.go @@ -68,6 +68,9 @@ const ( // // Process returns nil if the task is registered successfully, // otherwise returns non-nil error. +// +// opts specifies the behavior of task processing. If there are conflicting +// Option the last one overrides the ones before. func (c *Client) Process(task *Task, processAt time.Time, opts ...Option) error { opt := composeOptions(opts...) msg := &rdb.TaskMessage{ diff --git a/client_test.go b/client_test.go index 0d838f7..b71ece6 100644 --- a/client_test.go +++ b/client_test.go @@ -89,6 +89,24 @@ func TestClient(t *testing.T) { }, wantScheduled: nil, // db is flushed in setup so zset does not exist hence nil }, + { + desc: "Conflicting options", + task: task, + processAt: time.Now(), + opts: []Option{ + MaxRetry(2), + MaxRetry(10), + }, + wantEnqueued: []*rdb.TaskMessage{ + &rdb.TaskMessage{ + Type: task.Type, + Payload: task.Payload, + Retry: 10, // Last option takes precedence + Queue: "default", + }, + }, + wantScheduled: nil, // db is flushed in setup so zset does not exist hence nil + }, } for _, tc := range tests {