feat: read sandbox conf
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
张泊明518370910136 2024-06-30 02:42:51 -04:00
parent 2f8604f647
commit b608a22cfd
GPG Key ID: D47306D7062CDA9D
4 changed files with 22 additions and 6 deletions

View File

@ -10,9 +10,11 @@ import (
) )
type Conf struct { type Conf struct {
LogLevel int `default:"0"` SandboxExecServer string `default:"localhost:5051"`
OutputPath string `default:"joj3_result.json"` SandboxToken string `default:""`
Stages []struct { LogLevel int `default:"0"`
OutputPath string `default:"joj3_result.json"`
Stages []struct {
Name string Name string
Executor struct { Executor struct {
Name string Name string

View File

@ -5,7 +5,7 @@ import (
"log/slog" "log/slog"
"os" "os"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
@ -77,6 +77,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
setupSlog(conf) setupSlog(conf)
executors.InitWithConf(conf.SandboxExecServer, conf.SandboxToken)
stages := generateStages(conf) stages := generateStages(conf)
defer stage.Cleanup() defer stage.Cleanup()
results := stage.Run(stages) results := stage.Run(stages)

View File

@ -2,8 +2,13 @@ package executors
import ( import (
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/dummy" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/dummy"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/sandbox" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/sandbox"
) )
// this file does nothing but imports to ensure all the init() functions // this file does nothing but imports to ensure all the init() functions
// in the subpackages are called // in the subpackages are called
// overwrite the default registered executors
func InitWithConf(sandboxExecServer, sandboxToken string) {
sandbox.InitWithConf(sandboxExecServer, sandboxToken)
}

View File

@ -8,9 +8,17 @@ var name = "sandbox"
func init() { func init() {
stage.RegisterExecutor(name, &Sandbox{ stage.RegisterExecutor(name, &Sandbox{
// TODO: read from conf
execServer: "localhost:5051", execServer: "localhost:5051",
token: "", token: "",
cachedMap: make(map[string]string), cachedMap: make(map[string]string),
}) })
} }
// overwrite the default registered executor
func InitWithConf(execServer, token string) {
stage.RegisterExecutor(name, &Sandbox{
execServer: execServer,
token: token,
cachedMap: make(map[string]string),
})
}