forked from skynet-ltd/ghc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (65 loc) · 1.27 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"log"
"net/http"
"sync"
ghc "github.com/skynet-core/ghc-go"
)
func main() {
hc, err := ghc.New("http://0.0.0.0:8080/v1alpha1/graphql", &ghc.Options{
Header: http.Header{
"X-Hasura-Access-Key": []string{"SuperPassword"},
},
})
if err != nil {
log.Println(err)
return
}
var n int
ids := make([]int, 10000)
for i := 0; i < 10000; i++ {
res, err := hc.Execute(ghc.HasuraRequest(ghc.NewMutation(`mutation{
insert_job(objects:[{
op_id:624,
job_fields:{},
job_result:{},
job_type:"sales"
}]){
returning{
job_id
}
}
}`), nil))
if err != nil {
log.Fatalln(err)
}
if err = res.Data.Path("insert_job.returning.job_id").To(&[]*int{&n}); err != nil {
log.Fatalln(err)
}
ids[i] = n
}
wg := sync.WaitGroup{}
controller := make(chan struct{}, 300)
for _, id := range ids {
id := id
wg.Add(1)
controller <- struct{}{}
go func() {
defer func() {
wg.Done()
<-controller
}()
if _, err := hc.Execute(ghc.HasuraRequest(ghc.NewMutation(`mutation{
update_job(where:{job_id:{_eq:%d}},_set:{job_result:{status_code:200}}){
returning {
job_result
}
}
}`, id), nil)); err != nil {
log.Println(err)
}
}()
}
wg.Wait()
log.Println("DONE")
}