Beispiel #1
0
func execStartupTasks() {
	for _, task := range config.StartupTasks {
		runTask := func() {
			defer done.Done()
			done.Add(1)

			cc := new(run.CommandConfig)
			cc.Path = pathutils.FindLastFile(task.Path)
			cc.Args = task.Args
			cc.Logger = logger
			cc.TimeoutSecs = task.TimeoutSecs
			if task.Async {
				cc.StartupDelaySecs = task.StartupDelaySecs
				cc.StartupRandomDelaySecs = task.StartupRandomDelaySecs
			} else if cc.StartupDelaySecs > 0 || cc.StartupRandomDelaySecs > 0 {
				logger.Printf("WARNING: Only Async startup tasks may have startup delays.")
			}
			if _, err := run.RunCommand(cc, terminate); err != nil {
				logger.Printf("ERROR: Startup task '%s' reported: %v", cc.Path, err)
			}
		}
		if task.Async {
			go runTask()
		} else {
			runTask()
		}
	}
}
Beispiel #2
0
func setupScheduledTasks() {
	cronManager = cron.New()
	for _, task := range config.ScheduledTasks {
		cc := new(run.CommandConfig)
		cc.Path = pathutils.FindLastFile(task.Path)
		cc.Args = task.Args
		cc.Logger = logger
		cc.TimeoutSecs = task.TimeoutSecs
		cc.StartupDelaySecs = task.StartupDelaySecs
		cc.StartupRandomDelaySecs = task.StartupRandomDelaySecs
		runTask := func() {
			defer done.Done()
			done.Add(1)
			if _, err := run.RunCommand(cc, terminate); err != nil {
				logger.Printf("Error raised by scheduled task '%s': %v", cc.Path, err)
			}
		}
		err := cronManager.AddFunc(task.Schedule, runTask)
		if err != nil {
			logger.Printf("Unable to schedule task '%s': %v", task.Path, err)
		}
	}
	cronManager.Start()
}