func (d *Deployer) loop(w *state.UnitsWatcher) error { deployed, err := d.mgr.DeployedUnits() if err != nil { return err } for _, unitName := range deployed { d.deployed[unitName] = true if err := d.changed(unitName); err != nil { return err } } for { select { case <-d.tomb.Dying(): return tomb.ErrDying case changes, ok := <-w.Changes(): if !ok { return watcher.MustErr(w) } for _, unitName := range changes { if err := d.changed(unitName); err != nil { return err } } } } panic("unreachable") }
func newDeployer(st *state.State, w *state.UnitsWatcher, dataDir string) *deployer.Deployer { info := &state.Info{ EntityName: w.EntityName(), Addrs: st.Addrs(), CACert: st.CACert(), } mgr := newDeployManager(st, info, dataDir) return deployer.NewDeployer(st, mgr, w) }
// NewDeployer returns a Deployer that deploys and recalls unit agents via // mgr, according to membership and lifecycle changes notified by w. func NewDeployer(st *state.State, mgr Manager, w *state.UnitsWatcher) *Deployer { d := &Deployer{ st: st, mgr: mgr, entityName: w.EntityName(), deployed: map[string]bool{}, } go func() { defer d.tomb.Done() defer watcher.Stop(w, &d.tomb) d.tomb.Kill(d.loop(w)) }() return d }