package runner import ( "fmt" "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: fmt.Sprintf("%s:%d", conf.Redis.Address, conf.Redis.Port), 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 }