2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 23:32: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
import "github.com/google/uuid"
/*
TODOs:
- [P0] Write tests
@ -26,11 +28,16 @@ type Task struct {
// taskMessage is an internal representation of a task with additional metadata fields.
// This data gets written in redis.
type taskMessage struct {
// fields from type Task
//-------- Task fields --------
Type string
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 string

View File

@ -4,6 +4,7 @@ import (
"time"
"github.com/go-redis/redis/v7"
"github.com/google/uuid"
)
// 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.
func (c *Client) Process(task *Task, executeAt time.Time) error {
msg := &taskMessage{
ID: uuid.New(),
Type: task.Type,
Payload: task.Payload,
Queue: "default",

View File

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