2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-09-20 02:55:54 +08:00

Rename Client Process method to Schedule

This commit is contained in:
Ken Hibino 2020-01-03 20:24:18 -08:00
parent 9256fb6023
commit 606b0fae64
6 changed files with 13 additions and 13 deletions

View File

@ -73,13 +73,13 @@ func main() {
} }
// process the task immediately. // process the task immediately.
err := client.Process(&t1, time.Now()) err := client.Schedule(&t1, time.Now())
// process the task 24 hours later. // process the task 24 hours later.
err = client.Process(&t2, time.Now().Add(24 * time.Hour)) err = client.Schedule(&t2, time.Now().Add(24 * time.Hour))
// specify the max number of retry (default: 25) // specify the max number of retry (default: 25)
err = client.Process(&t1, time.Now(), asynq.MaxRetry(1)) err = client.Schedule(&t1, time.Now(), asynq.MaxRetry(1))
} }
``` ```

View File

@ -33,12 +33,12 @@ func TestBackground(t *testing.T) {
bg.start(HandlerFunc(h)) bg.start(HandlerFunc(h))
client.Process(&Task{ client.Schedule(&Task{
Type: "send_email", Type: "send_email",
Payload: map[string]interface{}{"recipient_id": 123}, Payload: map[string]interface{}{"recipient_id": 123},
}, time.Now()) }, time.Now())
client.Process(&Task{ client.Schedule(&Task{
Type: "send_email", Type: "send_email",
Payload: map[string]interface{}{"recipient_id": 456}, Payload: map[string]interface{}{"recipient_id": 456},
}, time.Now().Add(time.Hour)) }, time.Now().Add(time.Hour))

View File

@ -29,7 +29,7 @@ func BenchmarkEndToEndSimple(b *testing.B) {
// Create a bunch of tasks // Create a bunch of tasks
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
t := Task{Type: fmt.Sprintf("task%d", i), Payload: Payload{"data": i}} t := Task{Type: fmt.Sprintf("task%d", i), Payload: Payload{"data": i}}
client.Process(&t, time.Now()) client.Schedule(&t, time.Now())
} }
var wg sync.WaitGroup var wg sync.WaitGroup
@ -66,11 +66,11 @@ func BenchmarkEndToEnd(b *testing.B) {
// Create a bunch of tasks // Create a bunch of tasks
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
t := Task{Type: fmt.Sprintf("task%d", i), Payload: Payload{"data": i}} t := Task{Type: fmt.Sprintf("task%d", i), Payload: Payload{"data": i}}
client.Process(&t, time.Now()) client.Schedule(&t, time.Now())
} }
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
t := Task{Type: fmt.Sprintf("scheduled%d", i), Payload: Payload{"data": i}} t := Task{Type: fmt.Sprintf("scheduled%d", i), Payload: Payload{"data": i}}
client.Process(&t, time.Now().Add(time.Second)) client.Schedule(&t, time.Now().Add(time.Second))
} }
var wg sync.WaitGroup var wg sync.WaitGroup

View File

@ -70,14 +70,14 @@ const (
defaultMaxRetry = 25 defaultMaxRetry = 25
) )
// Process registers a task to be processed at the specified time. // Schedule registers a task to be processed at the specified time.
// //
// Process returns nil if the task is registered successfully, // Schedule returns nil if the task is registered successfully,
// otherwise returns non-nil error. // otherwise returns non-nil error.
// //
// opts specifies the behavior of task processing. If there are conflicting // opts specifies the behavior of task processing. If there are conflicting
// Option the last one overrides the ones before. // Option the last one overrides the ones before.
func (c *Client) Process(task *Task, processAt time.Time, opts ...Option) error { func (c *Client) Schedule(task *Task, processAt time.Time, opts ...Option) error {
opt := composeOptions(opts...) opt := composeOptions(opts...)
msg := &base.TaskMessage{ msg := &base.TaskMessage{
ID: xid.New(), ID: xid.New(),

View File

@ -117,7 +117,7 @@ func TestClient(t *testing.T) {
for _, tc := range tests { for _, tc := range tests {
h.FlushDB(t, r) // clean up db before each test case. h.FlushDB(t, r) // clean up db before each test case.
err := client.Process(tc.task, tc.processAt, tc.opts...) err := client.Schedule(tc.task, tc.processAt, tc.opts...)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
continue continue

2
doc.go
View File

@ -14,7 +14,7 @@ The Client is used to register a task to be processed at the specified time.
Payload: map[string]interface{}{"user_id": 42}, Payload: map[string]interface{}{"user_id": 42},
} }
err := client.Process(&t, time.Now().Add(time.Minute)) err := client.Schedule(&t, time.Now().Add(time.Minute))
The Background is used to run the background task processing with a given The Background is used to run the background task processing with a given
handler. handler.