コード例 #1
0
ファイル: main.go プロジェクト: mfya/autobld
func main() {
	c, err := config.Parse()
	if err != nil {
		log.Fatalf("Configuration error: %v", err)
	}

	watcher, err := config.SetupWatcher(c)
	if err != nil {
		log.Fatalf("Change detection failed: %v", err)
	}

	var (
		// errC is used to report errors. Any error will cause a log.Fatal
		errC = make(chan error)
		// signnalC is used for signals to this process (ctrl+c, etc).
		signalC = make(chan os.Signal)
	)
	signal.Notify(signalC, syscall.SIGINT, syscall.SIGKILL)

	// Start all the proxy listeners, and ensure they block initially till the task starts.
	var blockRequests sync.WaitGroup
	blockRequests.Add(1)
	for _, pc := range c.ProxyConfigs {
		proxy.Start(pc, &blockRequests, errC)
	}

	if err := eventLoop(c, errC, signalC, &blockRequests, watcher); err != nil {
		log.Fatalf("Error: %v", err)
	}
}
コード例 #2
0
ファイル: runner.go プロジェクト: mfya/autobld
// Reload will stop the task if it's running.
// To make sure the task is closed, a goroutine is set up to reprocess every second.
func (t *SM) Reload() {
	if t.PendingClose() {
		log.Fatalf("Reload called while already waiting for a close")
	}

	t.blockRequests.Add(1)
	t.reloadRequest = time.Now()
	if !t.Running() {
		log.L("Change detected, will start task in %v", t.c.ChangeTimeout)
		go func() {
			time.Sleep(t.c.ChangeTimeout)
			t.Reprocess <- struct{}{}
		}()
		return
	}

	log.L("Change detected, will restart task in %v", t.c.ChangeTimeout)
	go t.reloadCheck()
}