~ci-train-bot/account-polld/account-polld-ubuntu-yakkety-landing-079

« back to all changes in this revision

Viewing changes to cmd/account-polld/account_service.go

  • Committer: Bileto Bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2016-08-04 13:39:34 UTC
  • mfrom: (166.3.14 account-polld-caldav)
  • Revision ID: ci-train-bot@canonical.com-20160804133934-93z10me1ht8x95fe
Implement the caldav plugin to query for changes on caldav sources.

Approved by: Alberto Mardegan, Jonas G. Drange, system-apps-ci-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        "launchpad.net/ubuntu-push/click"
27
27
)
28
28
 
29
 
type AccountManager struct {
 
29
type AccountService struct {
30
30
        watcher          *accounts.Watcher
31
31
        authData         accounts.AuthData
32
32
        plugin           plugins.Plugin
51
51
        clickNotInstalledError = errors.New("Click not installed")
52
52
)
53
53
 
54
 
func NewAccountManager(watcher *accounts.Watcher, postWatch chan *PostWatch, plugin plugins.Plugin) *AccountManager {
55
 
        return &AccountManager{
 
54
func NewAccountService(watcher *accounts.Watcher, postWatch chan *PostWatch, plugin plugins.Plugin) *AccountService {
 
55
        return &AccountService{
56
56
                watcher:   watcher,
57
57
                plugin:    plugin,
58
58
                postWatch: postWatch,
61
61
        }
62
62
}
63
63
 
64
 
func (a *AccountManager) Delete() {
 
64
func (a *AccountService) Delete() {
65
65
        close(a.authChan)
66
66
        close(a.doneChan)
67
67
}
68
68
 
69
69
// Poll() always needs to be called asynchronously as otherwise qtcontacs' GetAvatar()
70
70
// will raise an error: "QSocketNotifier: Can only be used with threads started with QThread"
71
 
func (a *AccountManager) Poll(bootstrap bool) {
 
71
func (a *AccountService) Poll(bootstrap bool) {
72
72
        gotNewAuthData := false
73
 
        if !a.authData.Enabled {
74
 
                if a.authData, gotNewAuthData = <-a.authChan; !gotNewAuthData {
75
 
                        log.Println("Account", a.authData.AccountId, "no longer enabled")
76
 
                        return
77
 
                }
 
73
        if a.authData, gotNewAuthData = <-a.authChan; !gotNewAuthData {
 
74
                log.Println("Account", a.authData.AccountId, "no longer enabled")
 
75
                return
78
76
        }
79
77
 
80
78
        if a.penaltyCount > 0 {
126
124
                                        // and mark the data as disabled.
127
125
                                        // Do not refresh immediately when we just got new (faulty) auth data as immediately trying
128
126
                                        // again is probably not going to help. Instead, we wait for the next poll cycle.
129
 
                                        a.watcher.Refresh(a.authData.AccountId)
 
127
                                        a.watcher.Refresh(a.authData.AccountId, a.authData.ServiceName)
130
128
                                        a.authData.Enabled = false
131
129
                                        a.authData.Error = err
132
130
                                }
139
137
        log.Printf("Ending poll for account %d", a.authData.AccountId)
140
138
}
141
139
 
142
 
func (a *AccountManager) poll() {
 
140
func (a *AccountService) poll() {
143
141
        log.Println("Polling account", a.authData.AccountId)
144
142
        if !isClickInstalled(a.plugin.ApplicationId()) {
145
143
                log.Println(
167
165
        }
168
166
}
169
167
 
170
 
func (a *AccountManager) updateAuthData(authData accounts.AuthData) {
 
168
func (a *AccountService) updateAuthData(authData accounts.AuthData) {
171
169
        a.authChan <- authData
172
170
}
173
171