-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize.go
84 lines (69 loc) · 2.07 KB
/
initialize.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
82
83
84
package judger
import (
"context"
"encoding/json"
"github.com/Rabbit-OJ/Rabbit-OJ-Judger/config"
JudgerConfig "github.com/Rabbit-OJ/Rabbit-OJ-Judger/config"
"github.com/Rabbit-OJ/Rabbit-OJ-Judger/docker"
JudgerModels "github.com/Rabbit-OJ/Rabbit-OJ-Judger/models"
"github.com/Rabbit-OJ/Rabbit-OJ-Judger/mq"
)
type StorageGetFuncType = func(tid uint32, version string) ([]*JudgerModels.TestCaseType, error)
var (
StorageGetFunc StorageGetFuncType
)
func InitJudger(ctx context.Context, config *JudgerModels.JudgerConfigType, storageGetFunc StorageGetFuncType, withDocker bool, withKafka bool, role string) {
JudgerConfig.Global = config
JudgerConfig.Role = role
StorageGetFunc = storageGetFunc
Language()
if withDocker {
docker.InitDocker()
}
if withKafka {
MQ(ctx)
}
}
func MQ(ctx context.Context) {
mq.InitKafka(ctx)
if JudgerConfig.Role == "Judge" {
mq.JudgeRequestDeliveryChan = make(chan []byte)
mq.CreateJudgeRequestConsumer([]string{config.JudgeRequestTopicName}, "req1")
go JudgeRequestHandler()
}
if JudgerConfig.Role == "Server" {
mq.JudgeResponseDeliveryChan = make(chan []byte)
mq.CreateJudgeResponseConsumer([]string{config.JudgeResponseTopicName}, "res1")
go JudgeResultHandler()
}
}
func Language() {
languageCount := 0
for _, item := range config.Global.Languages {
if item.Enabled {
languageCount++
}
}
JudgerConfig.LocalImages = map[string]bool{}
JudgerConfig.CompileObject = map[string]JudgerModels.CompileInfo{}
JudgerConfig.SupportLanguage = make([]JudgerModels.SupportLanguage, languageCount)
for _, item := range config.Global.BuildImages {
JudgerConfig.LocalImages[item] = true
}
for index, item := range config.Global.Languages {
if !item.Enabled {
continue
}
JudgerConfig.SupportLanguage[index] = JudgerModels.SupportLanguage{
Name: item.Name,
Value: item.ID,
}
runArgsJson, err := json.Marshal(item.Args.RunArgs)
if err != nil {
panic(err)
}
currentCompileObject := item.Args
currentCompileObject.RunArgsJSON = string(runArgsJson)
JudgerConfig.CompileObject[item.ID] = currentCompileObject
}
}