diff --git a/CHANGELOG.md b/CHANGELOG.md index 97414f1..f06499a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Changed `Queue` function to not to convert the provided queue name to lowercase. Queue names are now case-sensitive. + ## [0.18.1] - 2020-07-04 ### Changed diff --git a/client.go b/client.go index cf67461..768135c 100644 --- a/client.go +++ b/client.go @@ -6,7 +6,6 @@ package asynq import ( "fmt" - "strings" "sync" "time" @@ -93,10 +92,8 @@ func (n retryOption) Type() OptionType { return MaxRetryOpt } func (n retryOption) Value() interface{} { return int(n) } // Queue returns an option to specify the queue to enqueue the task into. -// -// Queue name is case-insensitive and the lowercased version is used. func Queue(qname string) Option { - return queueOption(strings.ToLower(qname)) + return queueOption(qname) } func (qname queueOption) String() string { return fmt.Sprintf("Queue(%q)", string(qname)) } @@ -207,11 +204,11 @@ func composeOptions(opts ...Option) (option, error) { case retryOption: res.retry = int(opt) case queueOption: - trimmed := strings.TrimSpace(string(opt)) - if err := base.ValidateQueueName(trimmed); err != nil { + qname := string(opt) + if err := base.ValidateQueueName(qname); err != nil { return option{}, err } - res.queue = trimmed + res.queue = qname case timeoutOption: res.timeout = time.Duration(opt) case deadlineOption: diff --git a/client_test.go b/client_test.go index bc2a4ee..5a50a2f 100644 --- a/client_test.go +++ b/client_test.go @@ -287,13 +287,13 @@ func TestClientEnqueue(t *testing.T) { }, }, { - desc: "Queue option should be case-insensitive", + desc: "Queue option should be case sensitive", task: task, opts: []Option{ - Queue("HIGH"), + Queue("MyQueue"), }, wantInfo: &TaskInfo{ - Queue: "high", + Queue: "MyQueue", Type: task.Type(), Payload: task.Payload(), State: TaskStatePending, @@ -306,12 +306,12 @@ func TestClientEnqueue(t *testing.T) { NextProcessAt: now, }, wantPending: map[string][]*base.TaskMessage{ - "high": { + "MyQueue": { { Type: task.Type(), Payload: task.Payload(), Retry: defaultMaxRetry, - Queue: "high", + Queue: "MyQueue", Timeout: int64(defaultTimeout.Seconds()), Deadline: noDeadline.Unix(), }, diff --git a/internal/base/base.go b/internal/base/base.go index 54bd3de..e2e9126 100644 --- a/internal/base/base.go +++ b/internal/base/base.go @@ -10,6 +10,7 @@ import ( "crypto/md5" "encoding/hex" "fmt" + "strings" "sync" "time" @@ -85,7 +86,7 @@ func TaskStateFromString(s string) (TaskState, error) { // ValidateQueueName validates a given qname to be used as a queue name. // Returns nil if valid, otherwise returns non-nil error. func ValidateQueueName(qname string) error { - if len(qname) == 0 { + if len(strings.TrimSpace(qname)) == 0 { return fmt.Errorf("queue name must contain one or more characters") } return nil diff --git a/server.go b/server.go index 41cda4b..93d3c6a 100644 --- a/server.go +++ b/server.go @@ -295,6 +295,9 @@ func NewServer(r RedisConnOpt, cfg Config) *Server { } queues := make(map[string]int) for qname, p := range cfg.Queues { + if err := base.ValidateQueueName(qname); err != nil { + continue // ignore invalid queue names + } if p > 0 { queues[qname] = p }