long poller

This commit is contained in:
insanity@loafle.com 2017-04-25 15:19:00 +09:00
commit 448e2a97b9
3 changed files with 112 additions and 0 deletions

61
.gitignore vendored Normal file
View File

@ -0,0 +1,61 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Go template
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

41
poller.go Normal file
View File

@ -0,0 +1,41 @@
package long_poller_go
import (
"fmt"
"loafle.com/overflow/cron_go"
"sync"
)
var (
POLLING_ID = "OVERFLOW_LONG_POLLING"
DEFAULT_INTERVAL = uint64(3)
)
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()
})
}
func (p *LongPoller) startPolling() {
cr := &cron.Cron{}
p.runStat = cr.Start()
cr.AddTask(POLLING_ID, DEFAULT_INTERVAL).Invoke(p.poll, "agent0001")
}
func (p *LongPoller) Stop() {
p.runStat <- false
p.wg.Done()
}
func (p *LongPoller) poll(agentId string) {
fmt.Printf("%s :: LongPolling\n", agentId)
}

10
poller_test.go Normal file
View File

@ -0,0 +1,10 @@
package long_poller_go
import (
"testing"
)
func TestPolling(t *testing.T) {
poller := &LongPoller{}
poller.Start()
}