long poller

This commit is contained in:
insanity@loafle.com 2017-05-15 14:50:14 +09:00
parent 254b3f9392
commit 2627e114ff
3 changed files with 48 additions and 51 deletions

View File

@ -13,7 +13,6 @@ import (
const (
POLLING_ID = "OVERFLOW_LONG_POLLING"
DEFAULT_INTERVAL = uint64(3)
)
var (
@ -22,11 +21,11 @@ var (
)
type Poller struct {
once sync.Once
runStat chan bool
gconf *cm.GlobalConfig
scheduler *s.Scheduler
taskCh chan interface{}
once sync.Once
runStat chan bool
gconf *cm.GlobalConfig
scheduler *s.Scheduler
taskCh chan interface{}
}
func Start(conf *cm.GlobalConfig) (chan interface{}, error) {
@ -74,7 +73,6 @@ func (p *Poller) handleInterval(ch chan interface{}) {
func (p *Poller) Stop(ch chan interface{}) {
p.scheduler.Stop()
p.runStat <- false
p.removeAgentStopHandler(ch)
}
func (p *Poller) polling(agentId string) {
@ -113,7 +111,6 @@ func (p *Poller) updateInterval(interval string) {
p.scheduler.UpdateInterval(POLLING_ID, uint64(i))
}
/*
func printStatusStream(client pb.StatusClient) {
stream, err := client.Status(context.Background(), &pb.Empty{})

View File

@ -1,27 +1,27 @@
package long_poller_go
import (
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/observer/messages"
)
func handleConfigLoaded() {
ch := make(chan interface{}, 0)
observer.Add(messages.CFG_LOADED, ch)
startPoller(ch)
}
func (p *Poller) handleAgentStop() {
ch := make(chan interface{}, 0)
observer.Add(messages.AGT_STOPPED, ch)
_ = <- ch
p.Stop(ch)
}
func (p *Poller) removeConfigLoadedHandler(ch chan interface{}) {
observer.Remove(messages.CFG_LOADED, ch)
}
func (p *Poller) removeAgentStopHandler(ch chan interface{}) {
observer.Remove(messages.AGT_STOPPED, ch)
}
//import (
// "loafle.com/overflow/agent_api/observer"
// "loafle.com/overflow/agent_api/observer/messages"
//)
//
//func handleConfigLoaded() {
// ch := make(chan interface{}, 0)
// observer.Add(messages.CFG_LOADED, ch)
// startPoller(ch)
//}
//
//func (p *Poller) handleAgentStop() {
// ch := make(chan interface{}, 0)
// observer.Add(messages.AGT_STOPPED, ch)
// _ = <-ch
// p.Stop(ch)
//}
//
//func (p *Poller) removeConfigLoadedHandler(ch chan interface{}) {
// observer.Remove(messages.CFG_LOADED, ch)
//}
//
//func (p *Poller) removeAgentStopHandler(ch chan interface{}) {
// observer.Remove(messages.AGT_STOPPED, ch)
//}

View File

@ -1,20 +1,20 @@
package long_poller_go
import (
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/observer/messages"
"testing"
"time"
)
func TestPolling(t *testing.T) {
poller := &Poller{}
poller.start()
}
func TestTotal(t *testing.T) {
time.Sleep(time.Second * 5)
observer.Notify(messages.CFG_LOADED, "") //CONFIG LOCATION
time.Sleep(time.Second * 100)
}
//import (
// "loafle.com/overflow/agent_api/observer"
// "loafle.com/overflow/agent_api/observer/messages"
// "testing"
// "time"
//)
//
//func TestPolling(t *testing.T) {
// poller := &Poller{}
// poller.start()
//}
//
//func TestTotal(t *testing.T) {
// time.Sleep(time.Second * 5)
//
// observer.Notify(messages.CFG_LOADED, "") //CONFIG LOCATION
// time.Sleep(time.Second * 100)
//}