Skip to content

Instantly share code, notes, and snippets.

@Alex-Bond
Created January 8, 2019 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alex-Bond/6a64a714d6dcf5df8577fec3fd0a82cd to your computer and use it in GitHub Desktop.
Save Alex-Bond/6a64a714d6dcf5df8577fec3fd0a82cd to your computer and use it in GitHub Desktop.
for _, e := range config.Tasks {
err := c.AddFunc(e.Time, func() {
task := e
out, err := exec.Command("/bin/sh", "-c", task.Command).Output()
if err != nil {
raven.CaptureErrorAndWait(err, map[string]string{"command": e.Command, "time": task.Time})
log.Printf("%s: %s", e.Command, err)
}
if e.Output != nil {
f, err := os.OpenFile(*task.Output, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
raven.CaptureErrorAndWait(err, nil)
panic(err)
}
if _, err = f.WriteString(time.Now().Local().Format("2006-01-02 15:04:05") + " " + string(out[:])); err != nil {
raven.CaptureErrorAndWait(err, nil)
panic(err)
}
f.Close()
}
}, e.Name)
if err != nil {
raven.CaptureErrorAndWait(err, nil)
panic(fmt.Errorf("Fatal error cron init: %s \n", err))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment