2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-24 22:46:11 +08:00

Refactor redis keys and store messages in protobuf

Changes:
- Task messages are stored under "asynq:{<qname>}:t:<task_id>" key in redis, value is a HASH type and message are stored under "msg" key in the hash. The hash also stores "deadline", "timeout".
- Redis LIST and ZSET stores task message IDs
- Task messages are serialized using protocol buffer
This commit is contained in:
Ken Hibino
2021-03-12 16:23:08 -08:00
parent fdae82762c
commit d9481bd524
5 changed files with 124 additions and 1 deletions

View File

@@ -425,11 +425,19 @@ func (r *RDB) listZSetEntries(key, qname string, pgn Pagination) ([]base.Z, erro
s, err := cast.ToStringE(data[i])
if err != nil {
return nil, err
<<<<<<< HEAD
}
score, err := cast.ToInt64E(data[i+1])
if err != nil {
return nil, err
}
=======
}
score, err := cast.ToInt64E(data[i+1])
if err != nil {
return nil, err
}
>>>>>>> 138bd7f... Refactor redis keys and store messages in protobuf
msg, err := base.DecodeMessage([]byte(s))
if err != nil {
continue // bad data, ignore and continue

View File

@@ -101,7 +101,11 @@ func TestEnqueueUnique(t *testing.T) {
m1 := base.TaskMessage{
ID: uuid.New(),
Type: "email",
<<<<<<< HEAD
Payload: h.JSON(map[string]interface{}{"user_id": json.Number("123")}),
=======
Payload: map[string]interface{}{"user_id": json.Number("123")},
>>>>>>> 138bd7f... Refactor redis keys and store messages in protobuf
Queue: base.DefaultQueueName,
UniqueKey: base.UniqueKey(base.DefaultQueueName, "email", h.JSON(map[string]interface{}{"user_id": 123})),
}
@@ -157,7 +161,11 @@ func TestDequeue(t *testing.T) {
t1 := &base.TaskMessage{
ID: uuid.New(),
Type: "send_email",
<<<<<<< HEAD
Payload: h.JSON(map[string]interface{}{"subject": "hello!"}),
=======
Payload: map[string]interface{}{"subject": "hello!"},
>>>>>>> 138bd7f... Refactor redis keys and store messages in protobuf
Queue: "default",
Timeout: 1800,
Deadline: 0,
@@ -767,7 +775,11 @@ func TestRequeue(t *testing.T) {
func TestSchedule(t *testing.T) {
r := setup(t)
defer r.Close()
<<<<<<< HEAD
msg := h.NewTaskMessage("send_email", h.JSON(map[string]interface{}{"subject": "hello"}))
=======
msg := h.NewTaskMessage("send_email", map[string]interface{}{"subject": "hello"})
>>>>>>> 138bd7f... Refactor redis keys and store messages in protobuf
tests := []struct {
msg *base.TaskMessage
processAt time.Time
@@ -1475,7 +1487,11 @@ func TestWriteServerState(t *testing.T) {
Queues: map[string]int{"default": 2, "email": 5, "low": 1},
StrictPriority: false,
Started: time.Now().UTC(),
<<<<<<< HEAD
Status: "active",
=======
Status: "running",
>>>>>>> 138bd7f... Refactor redis keys and store messages in protobuf
ActiveWorkerCount: 0,
}
@@ -1565,7 +1581,11 @@ func TestWriteServerStateWithWorkers(t *testing.T) {
Queues: map[string]int{"default": 2, "email": 5, "low": 1},
StrictPriority: false,
Started: time.Now().Add(-10 * time.Minute).UTC(),
<<<<<<< HEAD
Status: "active",
=======
Status: "running",
>>>>>>> 138bd7f... Refactor redis keys and store messages in protobuf
ActiveWorkerCount: len(workers),
}