-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.go
59 lines (52 loc) · 1.12 KB
/
generator.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
package main
import (
"context"
"math/rand"
"sync"
"time"
)
type Generator struct {
Workers []*Worker
}
func NewGenerator(url string, numWorkers int) *Generator {
g := &Generator{}
for i := 0; i < numWorkers; i++ {
g.Workers = append(g.Workers, NewWorker(url))
}
return g
}
func (g *Generator) CreateCouriers() error {
for _, w := range g.Workers {
if err := w.CreateCourier(); err != nil {
return err
}
}
CourI = 0
return nil
}
func (g *Generator) CreateOrders(routesURL string, numberOfOrders int) error {
for _, w := range g.Workers {
for i := 0; i < rand.Intn(numberOfOrders); i++ {
if err := w.CreateOrder(routesURL); err != nil {
return err
}
}
}
AddrI = 0
return nil
}
func (g *Generator) DeleteCouriers() error {
for _, w := range g.Workers {
if err := w.DeleteCourier(); err != nil {
return err
}
}
return nil
}
func (g *Generator) UpdateWithInterval(wg *sync.WaitGroup, routeURL string, speed int, interval, throttle time.Duration, ctx context.Context) {
for _, w := range g.Workers {
wg.Add(1)
go w.UpdateLocation(wg, speed, routeURL, interval, ctx)
time.Sleep(throttle)
}
}