Skip to content

Commit

Permalink
chore(queue): update body to Payload
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Jan 20, 2022
1 parent 56600ec commit 600f61f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestGoroutinePanic(t *testing.T) {
func TestHandleTimeout(t *testing.T) {
job := Job{
Timeout: 100 * time.Millisecond,
Body: []byte("foo"),
Payload: []byte("foo"),
}
w := NewConsumer(
WithFn(func(ctx context.Context, m QueuedMessage) error {
Expand All @@ -257,7 +257,7 @@ func TestHandleTimeout(t *testing.T) {

job = Job{
Timeout: 150 * time.Millisecond,
Body: []byte("foo"),
Payload: []byte("foo"),
}

w = NewConsumer(
Expand All @@ -282,7 +282,7 @@ func TestHandleTimeout(t *testing.T) {
func TestJobComplete(t *testing.T) {
job := Job{
Timeout: 100 * time.Millisecond,
Body: []byte("foo"),
Payload: []byte("foo"),
}
w := NewConsumer(
WithFn(func(ctx context.Context, m QueuedMessage) error {
Expand All @@ -296,7 +296,7 @@ func TestJobComplete(t *testing.T) {

job = Job{
Timeout: 250 * time.Millisecond,
Body: []byte("foo"),
Payload: []byte("foo"),
}

w = NewConsumer(
Expand Down
19 changes: 11 additions & 8 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ type (
stopFlag int32
}

// Job with Timeout
// Job describes a task and its metadata.
Job struct {
Task TaskFunc `json:"-"`
Task TaskFunc `json:"-"`
// Timeout is the duration the task can be processed by Handler.
// zero if not specified
Timeout time.Duration `json:"timeout"`
Body []byte `json:"body"`
// Payload is the payload data of the task.
Payload []byte `json:"body"`
}
)

// Bytes get string body
func (j Job) Bytes() []byte {
return j.Body
return j.Payload
}

func (j Job) Encode() []byte {
Expand Down Expand Up @@ -125,11 +128,11 @@ func (q *Queue) handleQueue(timeout time.Duration, job QueuedMessage) error {

data := Job{
Timeout: timeout,
Body: job.Bytes(),
Payload: job.Bytes(),
}

return q.worker.Queue(Job{
Body: data.Encode(),
Payload: data.Encode(),
})
}

Expand All @@ -153,8 +156,8 @@ func (q *Queue) handleQueueTask(timeout time.Duration, task TaskFunc) error {
}

return q.worker.Queue(Job{
Task: task,
Body: data.Encode(),
Task: task,
Payload: data.Encode(),
})
}

Expand Down

0 comments on commit 600f61f

Please sign in to comment.