49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package runner
|
|
|
|
import (
|
|
"git.0x7f.app/WOJ/woj-server/internal/api/runner"
|
|
"git.0x7f.app/WOJ/woj-server/internal/misc/config"
|
|
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
|
|
"git.0x7f.app/WOJ/woj-server/internal/model"
|
|
"git.0x7f.app/WOJ/woj-server/pkg/utils"
|
|
"git.0x7f.app/WOJ/woj-server/pkg/zapasynq"
|
|
"github.com/hibiken/asynq"
|
|
"github.com/samber/do"
|
|
"go.uber.org/zap"
|
|
"runtime"
|
|
)
|
|
|
|
func RunRunner(i *do.Injector) error {
|
|
conf := do.MustInvoke[config.Service](i).GetConfig()
|
|
rlog := do.MustInvoke[log.Service](i).GetLogger("app.runner")
|
|
|
|
hnd, err := runner.NewRunner(i)
|
|
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: conf.Redis.Address,
|
|
Password: conf.Redis.Password,
|
|
DB: conf.Redis.QueueDb,
|
|
},
|
|
asynq.Config{
|
|
Concurrency: utils.If(runtime.NumCPU() > 1, runtime.NumCPU()-1, 1),
|
|
Logger: zapasynq.New(rlog),
|
|
Queues: map[string]int{model.QueueRunner: 1},
|
|
},
|
|
)
|
|
|
|
if err := srv.Run(mux); err != nil {
|
|
rlog.Warn("could not run server", zap.Error(err))
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|