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

View File

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

View File

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