コード例 #1
0
ファイル: canary.go プロジェクト: linearregression/canary-1
func (c *Canary) reloader() {
	if c.ReloadChan == nil {
		c.ReloadChan = make(chan manifest.Manifest)
	}

	for m := range c.ReloadChan {
		stoppingSensors := []sensor.Sensor{}
		for _, sensor := range c.Sensors {
			found := false
			for _, newTarget := range m.Targets {
				if newTarget.Hash == sensor.Target.Hash {
					found = true
				}
			}
			if !found {
				sensor.Stop()
				stoppingSensors = append(stoppingSensors, sensor)
			}

		}
		for _, sensor := range stoppingSensors {
			<-sensor.StopNotifyChan
		}

		c.Manifest = m
		if c.Config.RampupSensors {
			c.Manifest.GenerateRampupDelays(c.Config.DefaultSampleInterval)
		}
		// Start new sensors:
		c.startSensors()
	}
}
コード例 #2
0
ファイル: canary.go プロジェクト: linearregression/canary-1
func (c *Canary) SignalHandler() {
	signalChan := make(chan os.Signal, 1)
	signal.Notify(signalChan, syscall.SIGINT)
	signal.Notify(signalChan, syscall.SIGHUP)
	for s := range signalChan {
		switch s {
		case syscall.SIGINT:
			for _, sensor := range c.Sensors {
				sensor.Stop()
			}
			os.Exit(0)
		case syscall.SIGHUP:
			manifest, err := manifest.Get(c.Config.ManifestURL, c.Config.DefaultSampleInterval)
			if err != nil {
				log.Fatal(err)
			}
			// Split reload logic into reloader() as to allow other things to trigger a manifest reload
			c.ReloadChan <- manifest
		}
	}
}