Skip to content

Commit 600f61f

Browse files
committed
chore(queue): update body to Payload
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent 56600ec commit 600f61f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

consumer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func TestGoroutinePanic(t *testing.T) {
242242
func TestHandleTimeout(t *testing.T) {
243243
job := Job{
244244
Timeout: 100 * time.Millisecond,
245-
Body: []byte("foo"),
245+
Payload: []byte("foo"),
246246
}
247247
w := NewConsumer(
248248
WithFn(func(ctx context.Context, m QueuedMessage) error {
@@ -257,7 +257,7 @@ func TestHandleTimeout(t *testing.T) {
257257

258258
job = Job{
259259
Timeout: 150 * time.Millisecond,
260-
Body: []byte("foo"),
260+
Payload: []byte("foo"),
261261
}
262262

263263
w = NewConsumer(
@@ -282,7 +282,7 @@ func TestHandleTimeout(t *testing.T) {
282282
func TestJobComplete(t *testing.T) {
283283
job := Job{
284284
Timeout: 100 * time.Millisecond,
285-
Body: []byte("foo"),
285+
Payload: []byte("foo"),
286286
}
287287
w := NewConsumer(
288288
WithFn(func(ctx context.Context, m QueuedMessage) error {
@@ -296,7 +296,7 @@ func TestJobComplete(t *testing.T) {
296296

297297
job = Job{
298298
Timeout: 250 * time.Millisecond,
299-
Body: []byte("foo"),
299+
Payload: []byte("foo"),
300300
}
301301

302302
w = NewConsumer(

queue.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@ type (
2929
stopFlag int32
3030
}
3131

32-
// Job with Timeout
32+
// Job describes a task and its metadata.
3333
Job struct {
34-
Task TaskFunc `json:"-"`
34+
Task TaskFunc `json:"-"`
35+
// Timeout is the duration the task can be processed by Handler.
36+
// zero if not specified
3537
Timeout time.Duration `json:"timeout"`
36-
Body []byte `json:"body"`
38+
// Payload is the payload data of the task.
39+
Payload []byte `json:"body"`
3740
}
3841
)
3942

4043
// Bytes get string body
4144
func (j Job) Bytes() []byte {
42-
return j.Body
45+
return j.Payload
4346
}
4447

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

126129
data := Job{
127130
Timeout: timeout,
128-
Body: job.Bytes(),
131+
Payload: job.Bytes(),
129132
}
130133

131134
return q.worker.Queue(Job{
132-
Body: data.Encode(),
135+
Payload: data.Encode(),
133136
})
134137
}
135138

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

155158
return q.worker.Queue(Job{
156-
Task: task,
157-
Body: data.Encode(),
159+
Task: task,
160+
Payload: data.Encode(),
158161
})
159162
}
160163

0 commit comments

Comments
 (0)