// WatchForEnvironConfigChanges returns a NotifyWatcher that observes // changes to the environment configuration. // Note that although the NotifyWatchResult contains an Error field, // it's not used because we are only returning a single watcher, // so we use the regular error return. func (e *EnvironWatcher) WatchForEnvironConfigChanges() (params.NotifyWatchResult, error) { result := params.NotifyWatchResult{} canWatch, err := e.getCanWatch() if err != nil { return result, err } // TODO(dimitern) If we have multiple environments in state, use a // tag argument here and as a method argument. if !canWatch("") { return result, ErrPerm } watch := e.st.WatchForEnvironConfigChanges() // Consume the initial event. Technically, API // calls to Watch 'transmit' the initial event // in the Watch response. But NotifyWatchers // have no state to transmit. if _, ok := <-watch.Changes(); ok { result.NotifyWatcherId = e.resources.Register(watch) } else { return result, watcher.MustErr(watch) } return result, nil }
// WatchMachineErrorRetry returns a NotifyWatcher that notifies when // the provisioner should retry provisioning machines with transient errors. func (p *ProvisionerAPI) WatchMachineErrorRetry() (params.NotifyWatchResult, error) { result := params.NotifyWatchResult{} canWatch, err := p.getCanWatchMachines() if err != nil { return params.NotifyWatchResult{}, err } if !canWatch("") { return result, common.ErrPerm } watch := newWatchMachineErrorRetry() // Consume any initial event and forward it to the result. if _, ok := <-watch.Changes(); ok { result.NotifyWatcherId = p.resources.Register(watch) } else { return result, watcher.MustErr(watch) } return result, nil }