From dccb4512f91f95b04c1a0f0cb95a719845a79962 Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Thu, 27 Apr 2017 10:25:43 +0900 Subject: [PATCH] long poller --- poller.go | 33 ++++++++++++++++++++++++++------- poller_test.go | 5 +++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/poller.go b/poller.go index 0dde578..56c9ab8 100644 --- a/poller.go +++ b/poller.go @@ -10,23 +10,20 @@ import ( pb "loafle.com/overflow/crawler_go/grpc" //temp ) -var ( +const ( POLLING_ID = "OVERFLOW_LONG_POLLING" DEFAULT_INTERVAL = uint64(3) - API_SERVER_ADDR = "127.0.0.1:50052" + CENTRAL_ADDR = "127.0.0.1:50052" ) type LongPoller struct { once sync.Once runStat chan bool - wg sync.WaitGroup } func (p *LongPoller) Start() { p.once.Do(func() { - p.wg.Add(1) p.startPolling() - p.wg.Wait() }) } @@ -38,12 +35,11 @@ func (p *LongPoller) startPolling() { func (p *LongPoller) Stop() { p.runStat <- false - p.wg.Done() } func (p *LongPoller) polling(agentId string) { - conn, err := grpc.Dial(API_SERVER_ADDR, grpc.WithInsecure()) + conn, err := grpc.Dial(CENTRAL_ADDR, grpc.WithInsecure()) if err != nil { log.Println(err) return @@ -52,6 +48,9 @@ func (p *LongPoller) polling(agentId string) { //todo temporary client := pb.NewStatusClient(conn) + + //printStatus(client) //stream + out, err := client.Status(context.Background(), &pb.Empty{}) if err != nil { log.Println(err) @@ -68,3 +67,23 @@ func agentIdentifier() string { //todo return "agent000001" } + +/* +func printStassssssssstus(client pb.StatusClient) { + stream, err := client.Status(context.Background(), &pb.Empty{}) + if err != nil { + grpclog.Fatalf("%v.List(_) = _, %v", client, err) + } + for { + feature, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + grpclog.Fatalf("%v.List(_) = _, %v", client, err) + } + grpclog.Println(feature) + } + grpclog.Println("--------------------------") +} +*/ diff --git a/poller_test.go b/poller_test.go index f51114a..40f9705 100644 --- a/poller_test.go +++ b/poller_test.go @@ -1,10 +1,15 @@ package long_poller_go import ( + "log" "testing" + "time" ) func TestPolling(t *testing.T) { poller := &LongPoller{} poller.Start() + + log.Println("hihihihihi") + }