2022-10-22 17:38:39 +08:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
2023-07-14 21:47:11 +08:00
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/api/runner"
|
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/global"
|
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/model"
|
|
|
|
"git.0x7f.app/WOJ/woj-server/pkg/utils"
|
|
|
|
"git.0x7f.app/WOJ/woj-server/pkg/zapasynq"
|
2022-10-22 17:38:39 +08:00
|
|
|
"github.com/hibiken/asynq"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RunRunner(g *global.Global) error {
|
|
|
|
hnd, err := runner.NewRunner(g)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mux := asynq.NewServeMux()
|
|
|
|
mux.HandleFunc(model.TypeProblemBuild, hnd.Build)
|
|
|
|
mux.HandleFunc(model.TypeSubmitJudge, hnd.Judge)
|
|
|
|
|
|
|
|
srv := asynq.NewServer(
|
|
|
|
asynq.RedisClientOpt{
|
|
|
|
Addr: g.Conf.Redis.Address,
|
|
|
|
Password: g.Conf.Redis.Password,
|
|
|
|
DB: g.Conf.Redis.QueueDb,
|
|
|
|
},
|
|
|
|
asynq.Config{
|
2022-10-30 22:40:59 +08:00
|
|
|
Concurrency: utils.If(runtime.NumCPU() > 1, runtime.NumCPU()-1, 1),
|
2022-10-22 17:38:39 +08:00
|
|
|
Logger: zapasynq.New(g.Log),
|
|
|
|
Queues: map[string]int{model.QueueRunner: 1},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := srv.Run(mux); err != nil {
|
|
|
|
g.Log.Warn("could not run server", zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|