mirror of
https://github.com/hibiken/asynq.git
synced 2025-10-26 11:16:12 +08:00
Record total tasks processed/failed
This commit is contained in:
@@ -39,6 +39,12 @@ const (
|
||||
CancelChannel = "asynq:cancel" // PubSub channel
|
||||
)
|
||||
|
||||
// Max value for int64.
|
||||
//
|
||||
// Use this value to check if a redis counter value reached maximum.
|
||||
// As documeted in https://redis.io/commands/INCR, a string stored at a redis key is interpreted as a base-10 64 bit signed integer.
|
||||
const MaxInt64 = 1<<63 - 1
|
||||
|
||||
// TaskState denotes the state of a task.
|
||||
type TaskState int
|
||||
|
||||
@@ -150,6 +156,16 @@ func PausedKey(qname string) string {
|
||||
return fmt.Sprintf("%spaused", QueueKeyPrefix(qname))
|
||||
}
|
||||
|
||||
// ProcessedTotalKey returns a redis key for total processed count for the given queue.
|
||||
func ProcessedTotalKey(qname string) string {
|
||||
return fmt.Sprintf("%sprocessed", QueueKeyPrefix(qname))
|
||||
}
|
||||
|
||||
// FailedTotalKey returns a redis key for total failure count for the given queue.
|
||||
func FailedTotalKey(qname string) string {
|
||||
return fmt.Sprintf("%sfailed", QueueKeyPrefix(qname))
|
||||
}
|
||||
|
||||
// ProcessedKey returns a redis key for processed count for the given day for the queue.
|
||||
func ProcessedKey(qname string, t time.Time) string {
|
||||
return fmt.Sprintf("%sprocessed:%s", QueueKeyPrefix(qname), t.UTC().Format("2006-01-02"))
|
||||
|
||||
@@ -173,6 +173,40 @@ func TestPausedKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessedTotalKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
qname string
|
||||
want string
|
||||
}{
|
||||
{"default", "asynq:{default}:processed"},
|
||||
{"custom", "asynq:{custom}:processed"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
got := ProcessedTotalKey(tc.qname)
|
||||
if got != tc.want {
|
||||
t.Errorf("ProcessedTotalKey(%q) = %q, want %q", tc.qname, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailedTotalKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
qname string
|
||||
want string
|
||||
}{
|
||||
{"default", "asynq:{default}:failed"},
|
||||
{"custom", "asynq:{custom}:failed"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
got := FailedTotalKey(tc.qname)
|
||||
if got != tc.want {
|
||||
t.Errorf("FailedTotalKey(%q) = %q, want %q", tc.qname, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessedKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
qname string
|
||||
|
||||
Reference in New Issue
Block a user