event test

This commit is contained in:
geek 2017-04-28 12:37:33 +09:00
parent 3ec98f796b
commit 618339b086
2 changed files with 40 additions and 4 deletions

View File

@ -8,6 +8,14 @@ import (
q "loafle.com/overflow/queue_go"
"log"
"reflect"
"loafle.com/overflow/agent_api/observer"
"sync"
)
var (
instance *EventSender
once sync.Once
)
const (
@ -24,12 +32,38 @@ type Data struct {
FinishedAt uint64
}
func GetInstance() *EventSender {
once.Do(func() {
instance = &EventSender{}
})
return instance
}
func init() {
ch := make(chan interface{}, 0)
observer.Add(messages.CONFIGMANAGER_LOADED, ch)
handleInit(ch)
}
func handleInit(ch chan interface{}) {
es := GetInstance()
go func() {
data := <-ch
log.Println("handleInit", data)
//ds.gconf = data.(cm.ConfigManager).GetGlobalConfig()
es.start()
close(ch)
}()
}
type EventSender struct {
once sync.Once
lq *q.LoafleQueue
sc chan interface{}
}
func (es *EventSender) Start() {
func (es *EventSender) start() {
es.sc = make(chan interface{}, 0)
es.lq = q.NewQueue(messages.QUEUE_EVENT, DEFAULT_INTERVAL, es.sc)

View File

@ -11,11 +11,13 @@ import (
func TestEventSender_Start(t *testing.T) {
es := &EventSender{}
es.Start()
observer.Notify("CONFIGMANAGER_LOADED", nil)
time.Sleep(time.Second * 5)
testNotify()
time.Sleep(time.Second * 1000)
time.Sleep(time.Second * 100)
}