func loadFiles(c *internal.Cron) error { for _, file := range configFiles { if err := c.AddFile(file); err != nil { return err } } return nil }
func listen(c *internal.Cron) error { sigs := make(chan os.Signal, 1) done := make(chan error, 1) defer close(sigs) defer close(done) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGUSR1) go func() { for { sig := <-sigs switch sig { case syscall.SIGUSR1: logrus.Infof("Reloading config") c.Clear() if err := loadFiles(c); err != nil { done <- err return } c.Start() case syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL: logrus.Infof("Existing...") done <- c.Stop() return } } }() for { select { case err := <-done: return err case err := <-c.Event(): printEvent(err) } } }