long poller
This commit is contained in:
parent
59d517cb32
commit
dccb4512f9
33
poller.go
33
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("--------------------------")
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package long_poller_go
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPolling(t *testing.T) {
|
||||
poller := &LongPoller{}
|
||||
poller.Start()
|
||||
|
||||
log.Println("hihihihihi")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user