mirror of
https://github.com/hibiken/asynq.git
synced 2025-08-19 15:08:55 +08:00
Replace google/uuid package with rs/xid for more compact id
This commit is contained in:
@@ -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
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
// TODO(hibiken): Replace this with cmpopts.EquateApproxTime once it becomes availalble.
|
||||
@@ -310,7 +310,7 @@ func TestListScheduled(t *testing.T) {
|
||||
func TestListRetry(t *testing.T) {
|
||||
r := setup(t)
|
||||
m1 := &TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: xid.New(),
|
||||
Type: "send_email",
|
||||
Queue: "default",
|
||||
Payload: map[string]interface{}{"subject": "hello"},
|
||||
@@ -319,7 +319,7 @@ func TestListRetry(t *testing.T) {
|
||||
Retried: 10,
|
||||
}
|
||||
m2 := &TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: xid.New(),
|
||||
Type: "reindex",
|
||||
Queue: "default",
|
||||
Payload: nil,
|
||||
@@ -394,14 +394,14 @@ func TestListRetry(t *testing.T) {
|
||||
func TestListDead(t *testing.T) {
|
||||
r := setup(t)
|
||||
m1 := &TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: xid.New(),
|
||||
Type: "send_email",
|
||||
Queue: "default",
|
||||
Payload: map[string]interface{}{"subject": "hello"},
|
||||
ErrorMsg: "email server not responding",
|
||||
}
|
||||
m2 := &TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: xid.New(),
|
||||
Type: "reindex",
|
||||
Queue: "default",
|
||||
Payload: nil,
|
||||
@@ -485,7 +485,7 @@ func TestEnqueueDeadTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
dead []deadEntry
|
||||
score int64
|
||||
id uuid.UUID
|
||||
id xid.ID
|
||||
want error // expected return value from calling EnqueueDeadTask
|
||||
wantDead []*TaskMessage
|
||||
wantEnqueued []*TaskMessage
|
||||
@@ -561,7 +561,7 @@ func TestEnqueueRetryTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
dead []retryEntry
|
||||
score int64
|
||||
id uuid.UUID
|
||||
id xid.ID
|
||||
want error // expected return value from calling EnqueueRetryTask
|
||||
wantRetry []*TaskMessage
|
||||
wantEnqueued []*TaskMessage
|
||||
@@ -637,7 +637,7 @@ func TestEnqueueScheduledTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
dead []scheduledEntry
|
||||
score int64
|
||||
id uuid.UUID
|
||||
id xid.ID
|
||||
want error // expected return value from calling EnqueueScheduledTask
|
||||
wantScheduled []*TaskMessage
|
||||
wantEnqueued []*TaskMessage
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
// Redis keys
|
||||
@@ -51,7 +51,7 @@ type TaskMessage struct {
|
||||
|
||||
//-------- Metadata fields --------
|
||||
// ID is a unique identifier for each task
|
||||
ID uuid.UUID
|
||||
ID xid.ID
|
||||
// Queue is a name this message should be enqueued to
|
||||
Queue string
|
||||
// Retry is the max number of retry for this task.
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -40,7 +40,7 @@ var sortMsgOpt = cmp.Transformer("SortMsg", func(in []*TaskMessage) []*TaskMessa
|
||||
|
||||
func randomTask(taskType, qname string, payload map[string]interface{}) *TaskMessage {
|
||||
return &TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: xid.New(),
|
||||
Type: taskType,
|
||||
Queue: qname,
|
||||
Retry: 25,
|
||||
|
Reference in New Issue
Block a user