-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
62 lines (51 loc) · 1.15 KB
/
Copy pathutils.go
File metadata and controls
62 lines (51 loc) · 1.15 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
package main
import (
"bufio"
"encoding/csv"
"log"
"os"
"strconv"
"time"
)
func startSimulation(eventStreamPath string, action func(string, int)) {
file, err := os.Open(eventStreamPath)
if err != nil {
panic(err)
}
defer file.Close()
rdr := csv.NewReader(bufio.NewReader(file))
rows, err := rdr.ReadAll()
if err != nil {
panic(err)
}
stdTick := time.Now().UnixNano() / int64(time.Millisecond)
tick := 0
i := 0
for tick <= 60 * 10 * 1000 {
if i >= len(rows) {
break
}
row := rows[i]
startTime, _ := strconv.Atoi(row[1])
tick = int((time.Now().UnixNano() / int64(time.Millisecond)) - stdTick)
if tick >= startTime {
i += 1
go action(row[0], startTime)
} else {
time.Sleep(time.Second / 100)
}
}
}
func initLogger(fileName string) *log.Logger {
dirName := "logs/" + time.Now().Format("2006-01-02")
os.MkdirAll(dirName, 0755)
logFileName := dirName + "/" + time.Now().Format("15:04:05") + ".log"
if fileName != "" {
logFileName = fileName
}
outputFile, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
panic(err)
}
return log.New(outputFile, "", log.Ldate|log.Ltime)
}