Skip to content

Commit

Permalink
Allow upper case characters in queue name
Browse files Browse the repository at this point in the history
  • Loading branch information
hibiken committed Jul 15, 2021
1 parent c0ae624 commit 46b23d6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package asynq

import (
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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)) }
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
},
Expand Down
3 changes: 2 additions & 1 deletion internal/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 46b23d6

Please sign in to comment.