long poller
This commit is contained in:
parent
448e2a97b9
commit
c2b8b106ab
35
poller.go
35
poller.go
|
@ -2,13 +2,20 @@ package long_poller_go
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"loafle.com/overflow/cron_go"
|
||||
"sync"
|
||||
|
||||
"context"
|
||||
pb "loafle.com/overflow/crawler_go/grpc" //temp
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
POLLING_ID = "OVERFLOW_LONG_POLLING"
|
||||
DEFAULT_INTERVAL = uint64(3)
|
||||
DEFAULT_INTERVAL = uint64(5)
|
||||
API_SERVER_ADDR = "127.0.0.1:50052"
|
||||
)
|
||||
|
||||
type LongPoller struct {
|
||||
|
@ -28,7 +35,7 @@ func (p *LongPoller) Start() {
|
|||
func (p *LongPoller) startPolling() {
|
||||
cr := &cron.Cron{}
|
||||
p.runStat = cr.Start()
|
||||
cr.AddTask(POLLING_ID, DEFAULT_INTERVAL).Invoke(p.poll, "agent0001")
|
||||
cr.AddTask(POLLING_ID, DEFAULT_INTERVAL).Invoke(p.polling, agentIdentifier())
|
||||
}
|
||||
|
||||
func (p *LongPoller) Stop() {
|
||||
|
@ -36,6 +43,26 @@ func (p *LongPoller) Stop() {
|
|||
p.wg.Done()
|
||||
}
|
||||
|
||||
func (p *LongPoller) poll(agentId string) {
|
||||
fmt.Printf("%s :: LongPolling\n", agentId)
|
||||
func (p *LongPoller) polling(agentId string) {
|
||||
fmt.Printf("[%s] %s :: LongPolling\n", time.Now(), agentId)
|
||||
|
||||
conn, err := grpc.Dial(API_SERVER_ADDR, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
//todo temporary
|
||||
client := pb.NewStatusClient(conn)
|
||||
out, err := client.Status(context.Background(), &pb.Empty{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println(out)
|
||||
}
|
||||
|
||||
func agentIdentifier() string {
|
||||
//todo
|
||||
return "agent000001"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user