File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 1
1
# contrib
2
2
3
3
[ ![ Run Tests] ( https://github.com/golang-queue/contrib/actions/workflows/go.yml/badge.svg )] ( https://github.com/golang-queue/contrib/actions/workflows/go.yml )
4
+
5
+ ## Logger Interface
6
+
7
+ ``` go
8
+ type Logger interface {
9
+ Infof (format string , args ...interface {})
10
+ Errorf (format string , args ...interface {})
11
+ Fatalf (format string , args ...interface {})
12
+ Info (args ...interface {})
13
+ Error (args ...interface {})
14
+ Fatal (args ...interface {})
15
+ }
16
+ ```
17
+
18
+ * [x] zerolog
19
+
20
+ ## Example
21
+
22
+ zerolog
23
+
24
+ ``` go
25
+ package main
26
+
27
+ import (
28
+ " context"
29
+ " fmt"
30
+ " time"
31
+
32
+ " github.com/golang-queue/contrib/zerolog"
33
+ " github.com/golang-queue/queue"
34
+ )
35
+
36
+ func main () {
37
+ taskN := 100
38
+ rets := make (chan string , taskN)
39
+
40
+ // initial queue pool
41
+ q := queue.NewPool (5 , queue.WithLogger (zerolog.New ()))
42
+ // shutdown the service and notify all the worker
43
+ // wait all jobs are complete.
44
+ defer q.Release ()
45
+
46
+ // assign tasks in queue
47
+ for i := 0 ; i < taskN; i++ {
48
+ go func (i int ) {
49
+ if err := q.QueueTask (func (ctx context.Context ) error {
50
+ rets <- fmt.Sprintf (" Hi Gopher, handle the job: %02d " , +i)
51
+ return nil
52
+ }); err != nil {
53
+ panic (err)
54
+ }
55
+ }(i)
56
+ }
57
+
58
+ // wait until all tasks done
59
+ for i := 0 ; i < taskN; i++ {
60
+ fmt.Println (" message:" , <- rets)
61
+ time.Sleep (20 * time.Millisecond )
62
+ }
63
+ }
64
+ ```
You can’t perform that action at this time.
0 commit comments