Beispiel #1
3
func (a *aggregator) loop() error {
	var (
		next time.Time
		reqs []instanceInfoReq
	)

	for {
		var ready <-chan time.Time
		if !next.IsZero() {
			when := next.Add(a.config.Delay)
			ready = clock.Alarm(a.config.Clock, when)
		}
		select {
		case <-a.catacomb.Dying():
			return a.catacomb.ErrDying()

		case req := <-a.reqc:
			reqs = append(reqs, req)

			if next.IsZero() {
				next = a.config.Clock.Now()
			}

		case <-ready:
			if err := a.doRequests(reqs); err != nil {
				return errors.Trace(err)
			}
			next = time.Time{}
			reqs = nil
		}
	}
}
Beispiel #2
0
func (u *Undertaker) processDeadModel(deadSince time.Time) error {
	removeTime := deadSince.Add(u.config.RemoveDelay)
	select {
	case <-u.catacomb.Dying():
		return u.catacomb.ErrDying()
	case <-clock.Alarm(u.config.Clock, removeTime):
		err := u.config.Facade.RemoveModel()
		return errors.Annotate(err, "cannot remove model")
	}
}
Beispiel #3
0
// nextTick returns a channel that will send a value at some point when
// we expect to have to do some work; either because at least one lease
// may be ready to expire, or because enough enough time has passed that
// it's worth checking for stalled collaborators.
func (manager *Manager) nextTick() <-chan time.Time {
	now := manager.config.Clock.Now()
	nextTick := now.Add(manager.config.MaxSleep)
	for _, info := range manager.config.Client.Leases() {
		if info.Expiry.After(nextTick) {
			continue
		}
		nextTick = info.Expiry
	}
	logger.Debugf("waking to check leases at %s", nextTick)
	return clock.Alarm(manager.config.Clock, nextTick)
}
Beispiel #4
0
// nextExpiry returns a channel that will send a value at some point when we
// expect at least one lease to be ready to expire. If no leases are known,
// it will return nil.
func (manager *manager) nextExpiry() <-chan time.Time {
	var nextExpiry *time.Time
	for _, info := range manager.config.Client.Leases() {
		if nextExpiry != nil {
			if info.Expiry.After(*nextExpiry) {
				continue
			}
		}
		nextExpiry = &info.Expiry
	}
	if nextExpiry == nil {
		logger.Tracef("no leases recorded; never waking for expiry")
		return nil
	}
	logger.Tracef("waking to expire leases at %s", *nextExpiry)
	return clock.Alarm(manager.config.Clock, *nextExpiry)
}