コード例 #1
0
ファイル: scene.go プロジェクト: pellaeon/goas
// backendLoop runs the backend loop of the scene.
func (s *scene) backendLoop(l loop.Loop) (err error) {
	// Defer cleanup.
	defer func() {
		cerr := s.cleanupAllProps()
		if err == nil {
			err = cerr
		}
	}()
	// Init timers.
	var watchdog <-chan time.Time
	var clapperboard <-chan time.Time
	if s.absolute > 0 {
		clapperboard = time.After(s.absolute)
	}
	// Run loop.
	for {
		if s.inactivity > 0 {
			watchdog = time.After(s.inactivity)
		}
		select {
		case <-l.ShallStop():
			return nil
		case timeout := <-watchdog:
			return errors.New(ErrTimeout, errorMessages, "inactivity", timeout)
		case timeout := <-clapperboard:
			return errors.New(ErrTimeout, errorMessages, "absolute", timeout)
		case command := <-s.commandChan:
			s.processCommand(command)
		}
	}
}
コード例 #2
0
ファイル: monitoring.go プロジェクト: pellaeon/goas
// backendLoop runs the system monitor.
func (m *systemMonitor) backendLoop(l loop.Loop) error {
	// Init the monitor.
	m.init()
	// Run loop.
	for {
		select {
		case <-l.ShallStop():
			return nil
		case measuring := <-m.measuringChan:
			// Received a new measuring.
			if mp, ok := m.etmData[measuring.id]; ok {
				mp.update(measuring)
			} else {
				m.etmData[measuring.id] = newMeasuringPoint(measuring)
			}
		case ssvChange := <-m.ssvChangeChan:
			// Received a new change.
			if ssv, ok := m.ssvData[ssvChange.id]; ok {
				ssv.update(ssvChange)
			} else {
				m.ssvData[ssvChange.id] = newStaySetVariable(ssvChange)
			}
		case registration := <-m.retrieverRegistrationChan:
			// Received a new retriever for registration.
			m.dsrData[registration.id] = registration.dsr
		case cmd := <-m.commandChan:
			// Received a command to process.
			m.processCommand(cmd)
		}
	}
}
コード例 #3
0
ファイル: timex.go プロジェクト: pellaeon/goas
// backendLoop runs the server backend.
func (c *Crontab) backendLoop(l loop.Loop) error {
	for {
		select {
		case <-l.ShallStop():
			return nil
		case cmd := <-c.commandChan:
			if cmd.add {
				c.jobs[cmd.id] = cmd.job
			} else {
				delete(c.jobs, cmd.id)
			}
		case now := <-c.ticker.C:
			for id, job := range c.jobs {
				c.do(id, job, now)
			}
		}
	}
}