mirror of
https://github.com/hibiken/asynq.git
synced 2025-04-23 01:00:17 +08:00
Add CompletedKey and TaskStateCompleted to base package
This commit is contained in:
parent
40960d6acf
commit
1b8ba80a95
@ -48,6 +48,7 @@ const (
|
|||||||
TaskStateScheduled
|
TaskStateScheduled
|
||||||
TaskStateRetry
|
TaskStateRetry
|
||||||
TaskStateArchived
|
TaskStateArchived
|
||||||
|
TaskStateCompleted
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s TaskState) String() string {
|
func (s TaskState) String() string {
|
||||||
@ -62,6 +63,8 @@ func (s TaskState) String() string {
|
|||||||
return "retry"
|
return "retry"
|
||||||
case TaskStateArchived:
|
case TaskStateArchived:
|
||||||
return "archived"
|
return "archived"
|
||||||
|
case TaskStateCompleted:
|
||||||
|
return "completed"
|
||||||
}
|
}
|
||||||
panic(fmt.Sprintf("internal error: unknown task state %d", s))
|
panic(fmt.Sprintf("internal error: unknown task state %d", s))
|
||||||
}
|
}
|
||||||
@ -78,6 +81,8 @@ func TaskStateFromString(s string) (TaskState, error) {
|
|||||||
return TaskStateRetry, nil
|
return TaskStateRetry, nil
|
||||||
case "archived":
|
case "archived":
|
||||||
return TaskStateArchived, nil
|
return TaskStateArchived, nil
|
||||||
|
case "completed":
|
||||||
|
return TaskStateCompleted, nil
|
||||||
}
|
}
|
||||||
return 0, errors.E(errors.FailedPrecondition, fmt.Sprintf("%q is not supported task state", s))
|
return 0, errors.E(errors.FailedPrecondition, fmt.Sprintf("%q is not supported task state", s))
|
||||||
}
|
}
|
||||||
@ -136,6 +141,10 @@ func DeadlinesKey(qname string) string {
|
|||||||
return fmt.Sprintf("%sdeadlines", QueueKeyPrefix(qname))
|
return fmt.Sprintf("%sdeadlines", QueueKeyPrefix(qname))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CompletedKey(qname string) string {
|
||||||
|
return fmt.Sprintf("%scompleted", QueueKeyPrefix(qname))
|
||||||
|
}
|
||||||
|
|
||||||
// PausedKey returns a redis key to indicate that the given queue is paused.
|
// PausedKey returns a redis key to indicate that the given queue is paused.
|
||||||
func PausedKey(qname string) string {
|
func PausedKey(qname string) string {
|
||||||
return fmt.Sprintf("%spaused", QueueKeyPrefix(qname))
|
return fmt.Sprintf("%spaused", QueueKeyPrefix(qname))
|
||||||
|
@ -139,6 +139,23 @@ func TestArchivedKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompletedKey(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
qname string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"default", "asynq:{default}:completed"},
|
||||||
|
{"custom", "asynq:{custom}:completed"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
got := CompletedKey(tc.qname)
|
||||||
|
if got != tc.want {
|
||||||
|
t.Errorf("CompletedKey(%q) = %q, want %q", tc.qname, got, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPausedKey(t *testing.T) {
|
func TestPausedKey(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
qname string
|
qname string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user