-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
81 lines (77 loc) · 1.44 KB
/
runner.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
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"os"
"os/signal"
"strconv"
"syscall"
"time"
)
func skipNumber() (int, int) {
path := "data/" + kv
var num = 0
var suc = 0
var failed = 0
fileForEachLineCreate(path, func(line string) {
if num == 0 {
suc, _ = strconv.Atoi(line)
} else if num == 1 {
failed, _ = strconv.Atoi(line)
}
num += 1
})
return suc, failed
}
func runner() {
var suc, failed = skipNumber()
var counter = 0
stop := false
path := "data/origin/" + name
//path := "data/origin/test(unlabeled).csv"
c := make(chan os.Signal, 1)
st := make(chan bool, 1)
ch, pro := makeWorker(st)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("\r- Ctrl+C pressed in Terminal")
st <- true
stop = true
go func() {
time.Sleep(15 * time.Second)
fmt.Println("\r- Stop the world")
pro <- Progress{typ: 3}
}()
}()
go progressListener(pro, suc, failed)
fileForEachLine(path, func(line string) {
if !stop {
counter += 1
if counter > suc+failed {
url, typ := splitRow(line)
pro <- Progress{typ: 0}
ch <- Data{
url: url,
typ: typ,
}
}
}
})
}
func progressListener(progress chan Progress, suc int, failed int) {
all := 0
for {
event := <-progress
switch event.typ {
case 0:
all += 1
case 1:
suc += 1
case 2:
failed += 1
default:
stopTheWorld(suc, failed)
}
_, _ = fmt.Fprintf(os.Stdout, "Suc / Failed / All [%d/%d/%d]\n", suc, failed, all)
}
}