2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-26 11:16:12 +08:00

Replace google/uuid package with rs/xid for more compact id

This commit is contained in:
Ken Hibino
2019-12-11 07:38:24 -08:00
parent 8b6e3172ce
commit edcd70b221
11 changed files with 53 additions and 43 deletions

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/go-redis/redis/v7"
"github.com/google/uuid"
"github.com/rs/xid"
)
// Stats represents a state of queues at a certain time.
@@ -22,7 +22,7 @@ type Stats struct {
// EnqueuedTask is a task in a queue and is ready to be processed.
// Note: This is read only and used for monitoring purpose.
type EnqueuedTask struct {
ID uuid.UUID
ID xid.ID
Type string
Payload map[string]interface{}
}
@@ -30,7 +30,7 @@ type EnqueuedTask struct {
// InProgressTask is a task that's currently being processed.
// Note: This is read only and used for monitoring purpose.
type InProgressTask struct {
ID uuid.UUID
ID xid.ID
Type string
Payload map[string]interface{}
}
@@ -38,7 +38,7 @@ type InProgressTask struct {
// ScheduledTask is a task that's scheduled to be processed in the future.
// Note: This is read only and used for monitoring purpose.
type ScheduledTask struct {
ID uuid.UUID
ID xid.ID
Type string
Payload map[string]interface{}
ProcessAt time.Time
@@ -48,7 +48,7 @@ type ScheduledTask struct {
// RetryTask is a task that's in retry queue because worker failed to process the task.
// Note: This is read only and used for monitoring purpose.
type RetryTask struct {
ID uuid.UUID
ID xid.ID
Type string
Payload map[string]interface{}
// TODO(hibiken): add LastFailedAt time.Time
@@ -62,7 +62,7 @@ type RetryTask struct {
// DeadTask is a task in that has exhausted all retries.
// Note: This is read only and used for monitoring purpose.
type DeadTask struct {
ID uuid.UUID
ID xid.ID
Type string
Payload map[string]interface{}
LastFailedAt time.Time
@@ -233,7 +233,7 @@ func (r *RDB) ListDead() ([]*DeadTask, error) {
// EnqueueDeadTask finds a task that matches the given id and score from dead queue
// and enqueues it for processing. If a task that matches the id and score
// does not exist, it returns ErrTaskNotFound.
func (r *RDB) EnqueueDeadTask(id uuid.UUID, score int64) error {
func (r *RDB) EnqueueDeadTask(id xid.ID, score int64) error {
n, err := r.removeAndEnqueue(deadQ, id.String(), float64(score))
if err != nil {
return err
@@ -247,7 +247,7 @@ func (r *RDB) EnqueueDeadTask(id uuid.UUID, score int64) error {
// EnqueueRetryTask finds a task that matches the given id and score from retry queue
// and enqueues it for processing. If a task that matches the id and score
// does not exist, it returns ErrTaskNotFound.
func (r *RDB) EnqueueRetryTask(id uuid.UUID, score int64) error {
func (r *RDB) EnqueueRetryTask(id xid.ID, score int64) error {
n, err := r.removeAndEnqueue(retryQ, id.String(), float64(score))
if err != nil {
return err
@@ -261,7 +261,7 @@ func (r *RDB) EnqueueRetryTask(id uuid.UUID, score int64) error {
// EnqueueScheduledTask finds a task that matches the given id and score from scheduled queue
// and enqueues it for processing. If a task that matches the id and score does not
// exist, it returns ErrTaskNotFound.
func (r *RDB) EnqueueScheduledTask(id uuid.UUID, score int64) error {
func (r *RDB) EnqueueScheduledTask(id xid.ID, score int64) error {
n, err := r.removeAndEnqueue(scheduledQ, id.String(), float64(score))
if err != nil {
return err