forked from ZJGSU-Open-Source/GoOnlineJudge
-
Notifications
You must be signed in to change notification settings - Fork 5
/
init.go
57 lines (53 loc) · 1012 Bytes
/
init.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
package schedule
import (
"github.com/ZJGSU-ACM/GoOnlineJudge/config"
"github.com/ZJGSU-ACM/GoOnlineJudge/model"
"time"
)
type RemoteOJInterface interface {
Init()
Host() string
Ping() error
GetProblems() error
}
var ROJs = []RemoteOJInterface{&PKUJudger{}}
func init() {
go func() {
for _, oj := range ROJs {
oj.Init()
}
for {
errCnt := 0
for _, oj := range ROJs {
again:
if err := oj.GetProblems(); err != nil {
errCnt++
if errCnt > 5 {
continue
}
time.Sleep(10 * time.Second)
goto again
}
}
time.Sleep(7 * 24 * time.Hour) //update per week
}
}()
go func() {
ojModel := &model.OJModel{}
status := &model.OJStatus{}
for {
for _, oj := range ROJs {
err := oj.Ping()
status.Name = oj.Host()
if err != nil {
status.Status = config.StatusUnavailable
ojModel.Update(status)
} else {
status.Status = config.StatusOk
ojModel.Update(status)
}
}
time.Sleep(10 * time.Minute)
}
}()
}