mirror of
https://github.com/hibiken/asynq.git
synced 2025-04-21 16:20:18 +08:00
Add Priority type in base package
This commit is contained in:
parent
09ee8df5a0
commit
31a18d783e
@ -11,14 +11,33 @@ import (
|
|||||||
const (
|
const (
|
||||||
processedPrefix = "asynq:processed:" // STRING - asynq:processed:<yyyy-mm-dd>
|
processedPrefix = "asynq:processed:" // STRING - asynq:processed:<yyyy-mm-dd>
|
||||||
failurePrefix = "asynq:failure:" // STRING - asynq:failure:<yyyy-mm-dd>
|
failurePrefix = "asynq:failure:" // STRING - asynq:failure:<yyyy-mm-dd>
|
||||||
QueuePrefix = "asynq:queues:" // LIST - asynq:queues:<qname>
|
queuePrefix = "asynq:queues:" // LIST - asynq:queues:<qname>
|
||||||
DefaultQueue = QueuePrefix + "default" // LIST
|
DefaultQueue = queuePrefix + "default" // LIST
|
||||||
ScheduledQueue = "asynq:scheduled" // ZSET
|
ScheduledQueue = "asynq:scheduled" // ZSET
|
||||||
RetryQueue = "asynq:retry" // ZSET
|
RetryQueue = "asynq:retry" // ZSET
|
||||||
DeadQueue = "asynq:dead" // ZSET
|
DeadQueue = "asynq:dead" // ZSET
|
||||||
InProgressQueue = "asynq:in_progress" // LIST
|
InProgressQueue = "asynq:in_progress" // LIST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Priority indicates importance of a task in comparison with others.
|
||||||
|
type Priority int
|
||||||
|
|
||||||
|
// Levels of priority in descending order.
|
||||||
|
const (
|
||||||
|
PriorityHigh Priority = iota
|
||||||
|
PriorityDefault
|
||||||
|
PriorityLow
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p Priority) String() string {
|
||||||
|
return [...]string{"high", "default", "low"}[p]
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueueKey returns a redis key string for the given priority.
|
||||||
|
func QueueKey(p Priority) string {
|
||||||
|
return queuePrefix + p.String()
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessedKey returns a redis key string for procesed count
|
// ProcessedKey returns a redis key string for procesed count
|
||||||
// for the given day.
|
// for the given day.
|
||||||
func ProcessedKey(t time.Time) string {
|
func ProcessedKey(t time.Time) string {
|
||||||
|
@ -5,6 +5,24 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestQueueKey(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
p Priority
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{PriorityHigh, "asynq:queues:high"},
|
||||||
|
{PriorityDefault, "asynq:queues:default"},
|
||||||
|
{PriorityLow, "asynq:queues:low"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
got := QueueKey(tc.p)
|
||||||
|
if got != tc.want {
|
||||||
|
t.Errorf("QueueKey(%v) = %q, want %q", tc.p, got, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProcessedKey(t *testing.T) {
|
func TestProcessedKey(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
input time.Time
|
input time.Time
|
||||||
|
Loading…
x
Reference in New Issue
Block a user