2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 23:32:17 +08:00

Allow upper case characters in queue name

This commit is contained in:
Ken Hibino 2021-07-15 06:12:13 -07:00
parent c0ae62499f
commit 46b23d6495
5 changed files with 18 additions and 13 deletions

View File

@ -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

View File

@ -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:

View File

@ -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(),
},

View File

@ -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

View File

@ -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
}