Merge lp:~sergiusens/account-polld/interval into lp:~phablet-team/account-polld/trunk

Proposed by Sergio Schvezov
Status: Merged
Approved by: Roberto Alsina
Approved revision: 19
Merged at revision: 18
Proposed branch: lp:~sergiusens/account-polld/interval
Merge into: lp:~phablet-team/account-polld/trunk
Prerequisite: lp:~sergiusens/account-polld/click_poll_check
Diff against target: 56 lines (+19/-4)
1 file modified
cmd/account-polld/account_manager.go (+19/-4)
To merge this branch: bzr merge lp:~sergiusens/account-polld/interval
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+228197@code.launchpad.net

Commit message

Setting the interval to a more reasonable value. Allowing to override on start with an envvar

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
19. By Sergio Schvezov

Merged click_poll_check into interval.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cmd/account-polld/account_manager.go'
--- cmd/account-polld/account_manager.go 2014-07-24 21:16:18 +0000
+++ cmd/account-polld/account_manager.go 2014-07-24 21:16:18 +0000
@@ -19,6 +19,8 @@
1919
20import (20import (
21 "log"21 "log"
22 "os"
23 "strconv"
22 "sync"24 "sync"
23 "time"25 "time"
2426
@@ -36,7 +38,18 @@
36 terminate chan bool38 terminate chan bool
37}39}
3840
39const DEFAULT_INTERVAL = time.Duration(60 * time.Second)41var (
42 pollInterval = time.Duration(5 * time.Minute)
43 maxInterval = time.Duration(20 * time.Minute)
44)
45
46func init() {
47 if intervalEnv := os.Getenv("ACCOUNT_POLLD_POLL_INTERVAL_MINUTES"); intervalEnv != "" {
48 if interval, err := strconv.ParseInt(intervalEnv, 0, 0); err == nil {
49 pollInterval = time.Duration(interval) * time.Minute
50 }
51 }
52}
4053
41func NewAccountManager(authData accounts.AuthData, postWatch chan *PostWatch, plugin plugins.Plugin) *AccountManager {54func NewAccountManager(authData accounts.AuthData, postWatch chan *PostWatch, plugin plugins.Plugin) *AccountManager {
42 return &AccountManager{55 return &AccountManager{
@@ -44,7 +57,7 @@
44 authData: authData,57 authData: authData,
45 authMutex: &sync.Mutex{},58 authMutex: &sync.Mutex{},
46 postWatch: postWatch,59 postWatch: postWatch,
47 interval: DEFAULT_INTERVAL,60 interval: pollInterval,
48 terminate: make(chan bool),61 terminate: make(chan bool),
49 }62 }
50}63}
@@ -87,10 +100,12 @@
87 if n, err := a.plugin.Poll(&a.authData); err != nil {100 if n, err := a.plugin.Poll(&a.authData); err != nil {
88 log.Print("Error while polling ", a.authData.AccountId, ": ", err)101 log.Print("Error while polling ", a.authData.AccountId, ": ", err)
89 // penalizing the next poll102 // penalizing the next poll
90 a.interval += DEFAULT_INTERVAL103 if a.interval.Minutes() < maxInterval.Minutes() {
104 a.interval += pollInterval
105 }
91 } else if len(n) > 0 {106 } else if len(n) > 0 {
92 // on success we reset the timeout to the default interval107 // on success we reset the timeout to the default interval
93 a.interval = DEFAULT_INTERVAL108 a.interval = pollInterval
94 a.postWatch <- &PostWatch{messages: n, appId: a.plugin.ApplicationId()}109 a.postWatch <- &PostWatch{messages: n, appId: a.plugin.ApplicationId()}
95 }110 }
96}111}

Subscribers

People subscribed via source and target branches