-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_job.go
More file actions
70 lines (60 loc) · 1.22 KB
/
run_job.go
File metadata and controls
70 lines (60 loc) · 1.22 KB
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
package main
import (
"fmt"
"github.com/panjf2000/ants/v2"
"sync"
)
type RealJob struct {
round int
job *Job
pool *ants.PoolWithFunc
}
func (r *RealJob) String() string {
return fmt.Sprintf("[%d/%d]", r.round, config.TestTimes)
}
func runCommands(realJob *RealJob) {
// 按照执行次数要求反复创建任务
totalCount := 0
for _, command := range realJob.job.Commands {
g := sync.WaitGroup{}
if command.Type == "shell" {
totalCount = 1
} else { // pcap
totalCount = len(command.finder.pcaps)
}
round := 0
if RUNNING {
if command.Type == "shell" {
round++
realCommand := &RealCommand{
round: round,
total: totalCount,
command: command,
realJob: realJob,
g: &g,
}
g.Add(1)
_ = realJob.pool.Invoke(realCommand)
} else {
// pcap
for _, pcap := range command.finder.pcaps {
if !RUNNING {
return
}
round++
realCommand := &RealCommand{
round: round,
total: totalCount,
command: command,
pcap: pcap,
realJob: realJob,
g: &g,
}
g.Add(1)
_ = realJob.pool.Invoke(realCommand)
}
}
}
g.Wait() // commands in the same job runs sequentially
}
}