Only initial MaxConcurrentIOSPushes once. (#591)

This commit is contained in:
Bo-Yi Wu
2021-07-16 16:30:01 +08:00
committed by GitHub
parent ab8b1991ab
commit 73ff554b19
13 changed files with 106 additions and 107 deletions

View File

@@ -3,9 +3,7 @@ package queue
import (
"runtime"
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/logx"
"github.com/appleboy/gorush/queue/simple"
)
type (
@@ -20,21 +18,13 @@ type (
)
// NewQueue returns a Queue.
func NewQueue(cfg config.ConfYaml) *Queue {
func NewQueue(w Worker) *Queue {
q := &Queue{
workerCount: int(cfg.Core.WorkerNum),
queueCount: int(cfg.Core.QueueNum),
workerCount: runtime.NumCPU(),
queueCount: runtime.NumCPU() << 1,
routineGroup: newRoutineGroup(),
quit: make(chan struct{}),
worker: simple.NewWorker(cfg),
}
if q.workerCount != 0 {
q.workerCount = runtime.NumCPU()
}
if q.queueCount == 0 {
q.queueCount = runtime.NumCPU() << 1
worker: w,
}
return q
@@ -50,11 +40,6 @@ func (q *Queue) Usage() int {
return q.worker.Usage()
}
// Config update current config
func (q *Queue) Config(cfg config.ConfYaml) {
q.worker.Config(cfg)
}
// Start to enable all worker
func (q *Queue) Start() {
q.startWorker()

View File

@@ -3,20 +3,18 @@ package simple
import (
"errors"
"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/gorush"
)
// Worker for simple queue using channel
type Worker struct {
cfg config.ConfYaml
queueNotification chan gorush.PushNotification
}
// Run start the worker
func (s *Worker) Run(_ chan struct{}) {
for notification := range s.queueNotification {
gorush.SendNotification(s.cfg, notification)
gorush.SendNotification(notification)
}
}
@@ -45,15 +43,9 @@ func (s *Worker) Enqueue(job interface{}) error {
}
}
// Config update current config
func (s *Worker) Config(cfg config.ConfYaml) {
s.cfg = cfg
}
// NewWorker for struct
func NewWorker(cfg config.ConfYaml) *Worker {
func NewWorker(num int) *Worker {
return &Worker{
cfg: cfg,
queueNotification: make(chan gorush.PushNotification, cfg.Core.QueueNum),
queueNotification: make(chan gorush.PushNotification, num),
}
}

View File

@@ -1,7 +1,5 @@
package queue
import "github.com/appleboy/gorush/config"
// Worker interface
type Worker interface {
Run(chan struct{})
@@ -9,5 +7,4 @@ type Worker interface {
Enqueue(job interface{}) error
Capacity() int
Usage() int
Config(config.ConfYaml)
}