woj-server/internal/app/runner/runner.go

48 lines
1.2 KiB
Go

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/zapasynq"
"github.com/hibiken/asynq"
"github.com/samber/do"
"go.uber.org/zap"
)
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: 1, // there's a worker pool in runner service
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
}