make event manager just do initial only once

pull/385/head
Michael Li 2 years ago
parent 65dc7d0738
commit da4f2f1810
No known key found for this signature in database

@ -5,13 +5,18 @@
package events package events
import ( import (
"sync"
"github.com/alimy/tryst/event" "github.com/alimy/tryst/event"
"github.com/alimy/tryst/pool" "github.com/alimy/tryst/pool"
"github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/conf"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var _defaultEventManager event.EventManager var (
_defaultEventManager event.EventManager
_onceInitial sync.Once
)
// OnEvent push event to gorotine pool then handled automatic. // OnEvent push event to gorotine pool then handled automatic.
func OnEvent(event event.Event) { func OnEvent(event event.Event) {
@ -19,27 +24,29 @@ func OnEvent(event event.Event) {
} }
func Initial() { func Initial() {
var opts []pool.Option _onceInitial.Do(func() {
s := conf.EventManagerSetting var opts []pool.Option
if s.MinWorker > 5 { s := conf.EventManagerSetting
opts = append(opts, pool.MinWorkerOpt(s.MinWorker)) if s.MinWorker > 5 {
} else { opts = append(opts, pool.MinWorkerOpt(s.MinWorker))
opts = append(opts, pool.MinWorkerOpt(5)) } else {
} opts = append(opts, pool.MinWorkerOpt(5))
if s.MaxEventBuf > 10 { }
opts = append(opts, pool.MaxRequestBufOpt(s.MaxEventBuf)) if s.MaxEventBuf > 10 {
} else { opts = append(opts, pool.MaxRequestBufOpt(s.MaxEventBuf))
opts = append(opts, pool.MaxRequestBufOpt(10)) } else {
} opts = append(opts, pool.MaxRequestBufOpt(10))
if s.MaxTempEventBuf > 10 { }
opts = append(opts, pool.MaxRequestTempBufOpt(s.MaxTempEventBuf)) if s.MaxTempEventBuf > 10 {
} else { opts = append(opts, pool.MaxRequestTempBufOpt(s.MaxTempEventBuf))
opts = append(opts, pool.MaxRequestTempBufOpt(10)) } else {
} opts = append(opts, pool.MaxRequestTempBufOpt(10))
opts = append(opts, pool.MaxTickCountOpt(s.MaxTickCount), pool.TickWaitTimeOpt(s.TickWaitTime)) }
_defaultEventManager = event.NewEventManager(func(req event.Event, err error) { opts = append(opts, pool.MaxTickCountOpt(s.MaxTickCount), pool.TickWaitTimeOpt(s.TickWaitTime))
logrus.Errorf("handle event[%s] occurs error: %s", req.Name(), err) _defaultEventManager = event.NewEventManager(func(req event.Event, err error) {
}, opts...) logrus.Errorf("handle event[%s] occurs error: %s", req.Name(), err)
}, opts...)
})
} }
func Restart() { func Restart() {

Loading…
Cancel
Save