feat: #6 [1] Add pool in runner

This commit is contained in:
Paul Pan 2024-01-06 15:06:12 +08:00
parent e35674dbaa
commit 8d66639cdc
Signed by: Paul
GPG Key ID: D639BDF5BA578AF4
2 changed files with 8 additions and 3 deletions

View File

@ -6,12 +6,10 @@ import (
"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 {
@ -34,7 +32,7 @@ func RunRunner(i *do.Injector) error {
DB: conf.Redis.QueueDb,
},
asynq.Config{
Concurrency: utils.If(runtime.NumCPU() > 1, runtime.NumCPU()-1, 1),
Concurrency: 1, // there's a worker pool in runner service
Logger: zapasynq.New(rlog),
Queues: map[string]int{model.QueueRunner: 1},
},

View File

@ -4,8 +4,11 @@ import (
"git.0x7f.app/WOJ/woj-server/internal/e"
"git.0x7f.app/WOJ/woj-server/internal/misc/config"
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
"git.0x7f.app/WOJ/woj-server/pkg/pool"
"git.0x7f.app/WOJ/woj-server/pkg/utils"
"github.com/samber/do"
"go.uber.org/zap"
"runtime"
)
var _ Service = (*service)(nil)
@ -30,14 +33,18 @@ type Service interface {
}
func NewService(i *do.Injector) (Service, error) {
concurrency := utils.If(runtime.NumCPU() > 1, runtime.NumCPU()-1, 1)
return &service{
log: do.MustInvoke[log.Service](i).GetLogger("runner"),
pool: pool.NewTaskPool(concurrency, concurrency),
verbose: do.MustInvoke[config.Service](i).GetConfig().Development,
}, nil
}
type service struct {
log *zap.Logger
pool *pool.TaskPool
verbose bool
}