-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer.go
47 lines (43 loc) · 1.47 KB
/
timer.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
package together
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"time"
)
func request(msgType string, podName string, group string, uid string) {
resp, err := http.PostForm("http://localhost:8080/msgRequest", url.Values{"msgType": {msgType}, "podName": {podName}, "group": {group}, "uid":{uid}})
if err != nil {
panic(err)
}
defer resp.Body.Close()
// Response 체크.
respBody, err := ioutil.ReadAll(resp.Body)
if err == nil {
str := string(respBody)
println(str)
}
}
func scheduler(startHour string, startMinute string, endHour string, endMinute string, podName string, group string, uid string) {
year, month, day := time.Now().Date()
startTimeStr := fmt.Sprint(year, "-", int(month), "-", day, " ", startHour, ":", startMinute)
endTimeStr := fmt.Sprint(year, "-", int(month), "-", day, " ", endHour, ":", endMinute)
loc, _ := time.LoadLocation("Asia/Seoul")
startTime, _ := time.ParseInLocation("2006-01-02 15:04", startTimeStr, loc)
endTime, _ := time.ParseInLocation("2006-01-02 15:04", endTimeStr, loc)
startDuration := startTime.Sub(time.Now())
endDuration := endTime.Sub(time.Now())
time.AfterFunc(startDuration-10*time.Minute, func() {
request("readyReminder", podName, group, uid)
})
time.AfterFunc(startDuration, func() {
request("startPod", podName, group, uid)
})
time.AfterFunc(endDuration, func() {
request("endPod", podName, group, uid)
})
time.AfterFunc(endDuration+10*time.Minute, func() {
request("deletePod", podName, group, uid)
})
}