forked from gocelery/gocelery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_client_named_arg_test.go
58 lines (47 loc) · 1.04 KB
/
example_client_named_arg_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2019 Sick Yoon
// This file is part of gocelery which is released under MIT license.
// See file LICENSE for full license details.
package gocelery
import (
"context"
"log"
"math/rand"
"reflect"
"time"
"github.com/redis/go-redis/v9"
)
func Example_clientWithNamedArguments() {
connectOpions, err := redis.ParseURL("redis://")
if err != nil {
panic(err)
}
client := redis.NewClient(connectOpions)
// initialize celery client
cli, _ := NewCeleryClient(
NewRedisBroker(client),
&RedisCeleryBackend{UniversalClient: client},
1,
)
// prepare arguments
taskName := "worker.add"
argA := rand.Intn(10)
argB := rand.Intn(10)
// run task
asyncResult, err := cli.DelayKwargs(
context.Background(),
taskName,
map[string]interface{}{
"a": argA,
"b": argB,
},
)
if err != nil {
panic(err)
}
// get results from backend with timeout
res, err := asyncResult.Get(context.Background(), 10*time.Second)
if err != nil {
panic(err)
}
log.Printf("result: %+v of type %+v", res, reflect.TypeOf(res))
}