mirror of
https://github.com/hibiken/asynq.git
synced 2025-10-04 05:32:01 +08:00
Record processed and failure daily count
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
// Package base defines foundational types and constants used in asynq package.
|
||||
package base
|
||||
|
||||
import "github.com/rs/xid"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
// Redis keys
|
||||
const (
|
||||
QueuePrefix = "asynq:queues:" // LIST - asynq:queues:<qname>
|
||||
processedPrefix = "asynq:processed:" // STRING - asynq:processed:<yyyy-mm-dd>
|
||||
failurePrefix = "asynq:failure:" // STRING - asynq:failure:<yyyy-mm-dd>
|
||||
QueuePrefix = "asynq:queues:" // LIST - asynq:queues:<qname>
|
||||
DefaultQueue = QueuePrefix + "default" // LIST
|
||||
ScheduledQueue = "asynq:scheduled" // ZSET
|
||||
RetryQueue = "asynq:retry" // ZSET
|
||||
@@ -13,6 +19,18 @@ const (
|
||||
InProgressQueue = "asynq:in_progress" // LIST
|
||||
)
|
||||
|
||||
// ProcessedKey returns a redis key string for procesed count
|
||||
// for the given day.
|
||||
func ProcessedKey(t time.Time) string {
|
||||
return processedPrefix + t.UTC().Format("2006-01-02")
|
||||
}
|
||||
|
||||
// FailureKey returns a redis key string for failure count
|
||||
// for the given day.
|
||||
func FailureKey(t time.Time) string {
|
||||
return failurePrefix + t.UTC().Format("2006-01-02")
|
||||
}
|
||||
|
||||
// TaskMessage is the internal representation of a task with additional metadata fields.
|
||||
// Serialized data of this type gets written in redis.
|
||||
type TaskMessage struct {
|
||||
|
42
internal/base/base_test.go
Normal file
42
internal/base/base_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestProcessedKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
input time.Time
|
||||
want string
|
||||
}{
|
||||
{time.Date(2019, 11, 14, 10, 30, 1, 1, time.UTC), "asynq:processed:2019-11-14"},
|
||||
{time.Date(2020, 12, 1, 1, 0, 1, 1, time.UTC), "asynq:processed:2020-12-01"},
|
||||
{time.Date(2020, 1, 6, 15, 02, 1, 1, time.UTC), "asynq:processed:2020-01-06"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
got := ProcessedKey(tc.input)
|
||||
if got != tc.want {
|
||||
t.Errorf("ProcessedKey(%v) = %q, want %q", tc.input, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailureKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
input time.Time
|
||||
want string
|
||||
}{
|
||||
{time.Date(2019, 11, 14, 10, 30, 1, 1, time.UTC), "asynq:failure:2019-11-14"},
|
||||
{time.Date(2020, 12, 1, 1, 0, 1, 1, time.UTC), "asynq:failure:2020-12-01"},
|
||||
{time.Date(2020, 1, 6, 15, 02, 1, 1, time.UTC), "asynq:failure:2020-01-06"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
got := FailureKey(tc.input)
|
||||
if got != tc.want {
|
||||
t.Errorf("FailureKey(%v) = %q, want %q", tc.input, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user