mirror of
https://github.com/hibiken/asynq.git
synced 2024-11-10 11:31:58 +08:00
Add ID field to taskMessage
This commit is contained in:
parent
67a9e8aa00
commit
80f477212d
11
asynq.go
11
asynq.go
@ -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
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user