feat: #6 [1] Add pool in runner
This commit is contained in:
parent
e35674dbaa
commit
8d66639cdc
@ -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},
|
||||
},
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user