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
1=== modified file 'cmd/account-polld/account_manager.go'
2--- cmd/account-polld/account_manager.go 2014-07-24 21:16:18 +0000
3+++ cmd/account-polld/account_manager.go 2014-07-24 21:16:18 +0000
4@@ -19,6 +19,8 @@
5
6 import (
7 "log"
8+ "os"
9+ "strconv"
10 "sync"
11 "time"
12
13@@ -36,7 +38,18 @@
14 terminate chan bool
15 }
16
17-const DEFAULT_INTERVAL = time.Duration(60 * time.Second)
18+var (
19+ pollInterval = time.Duration(5 * time.Minute)
20+ maxInterval = time.Duration(20 * time.Minute)
21+)
22+
23+func init() {
24+ if intervalEnv := os.Getenv("ACCOUNT_POLLD_POLL_INTERVAL_MINUTES"); intervalEnv != "" {
25+ if interval, err := strconv.ParseInt(intervalEnv, 0, 0); err == nil {
26+ pollInterval = time.Duration(interval) * time.Minute
27+ }
28+ }
29+}
30
31 func NewAccountManager(authData accounts.AuthData, postWatch chan *PostWatch, plugin plugins.Plugin) *AccountManager {
32 return &AccountManager{
33@@ -44,7 +57,7 @@
34 authData: authData,
35 authMutex: &sync.Mutex{},
36 postWatch: postWatch,
37- interval: DEFAULT_INTERVAL,
38+ interval: pollInterval,
39 terminate: make(chan bool),
40 }
41 }
42@@ -87,10 +100,12 @@
43 if n, err := a.plugin.Poll(&a.authData); err != nil {
44 log.Print("Error while polling ", a.authData.AccountId, ": ", err)
45 // penalizing the next poll
46- a.interval += DEFAULT_INTERVAL
47+ if a.interval.Minutes() < maxInterval.Minutes() {
48+ a.interval += pollInterval
49+ }
50 } else if len(n) > 0 {
51 // on success we reset the timeout to the default interval
52- a.interval = DEFAULT_INTERVAL
53+ a.interval = pollInterval
54 a.postWatch <- &PostWatch{messages: n, appId: a.plugin.ApplicationId()}
55 }
56 }

Subscribers

People subscribed via source and target branches