2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-26 07:42:17 +08:00

Add ID field to taskMessage

This commit is contained in:
Ken Hibino 2019-11-22 06:16:43 -08:00
parent 67a9e8aa00
commit 80f477212d
3 changed files with 14 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package asynq package asynq
import "github.com/google/uuid"
/* /*
TODOs: TODOs:
- [P0] Write tests - [P0] Write tests
@ -26,11 +28,16 @@ type Task struct {
// taskMessage is an internal representation of a task with additional metadata fields. // taskMessage is an internal representation of a task with additional metadata fields.
// This data gets written in redis. // This data gets written in redis.
type taskMessage struct { type taskMessage struct {
// fields from type Task //-------- Task fields --------
Type string Type string
Payload map[string]interface{} Payload map[string]interface{}
//------- metadata fields ---------- //-------- metadata fields --------
// unique identifier for each task
ID uuid.UUID
// queue name this message should be enqueued to // queue name this message should be enqueued to
Queue string Queue string

View File

@ -4,6 +4,7 @@ import (
"time" "time"
"github.com/go-redis/redis/v7" "github.com/go-redis/redis/v7"
"github.com/google/uuid"
) )
// Client is an interface for scheduling tasks. // Client is an interface for scheduling tasks.
@ -20,6 +21,7 @@ func NewClient(opt *RedisOpt) *Client {
// Process enqueues the task to be performed at a given time. // Process enqueues the task to be performed at a given time.
func (c *Client) Process(task *Task, executeAt time.Time) error { func (c *Client) Process(task *Task, executeAt time.Time) error {
msg := &taskMessage{ msg := &taskMessage{
ID: uuid.New(),
Type: task.Type, Type: task.Type,
Payload: task.Payload, Payload: task.Payload,
Queue: "default", Queue: "default",

View File

@ -7,6 +7,7 @@ import (
"github.com/go-redis/redis/v7" "github.com/go-redis/redis/v7"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/uuid"
) )
var client *redis.Client var client *redis.Client
@ -28,6 +29,7 @@ func setup() *rdb {
func TestPush(t *testing.T) { func TestPush(t *testing.T) {
r := setup() r := setup()
msg := &taskMessage{ msg := &taskMessage{
ID: uuid.New(),
Type: "sendEmail", Type: "sendEmail",
Queue: "default", Queue: "default",
Retry: 10, Retry: 10,
@ -54,6 +56,7 @@ func TestPush(t *testing.T) {
func TestDequeueImmediateReturn(t *testing.T) { func TestDequeueImmediateReturn(t *testing.T) {
r := setup() r := setup()
msg := &taskMessage{ msg := &taskMessage{
ID: uuid.New(),
Type: "GenerateCSVExport", Type: "GenerateCSVExport",
Queue: "csv", Queue: "csv",
Retry: 10, Retry: 10,