Guest User

Untitled

a guest
Jan 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "log"
  5. "fmt"
  6. "time"
  7. "github.com/jakecoffman/cron"
  8. )
  9.  
  10.  
  11. func main() {
  12.  
  13. //Every 5 seconds
  14. var c = cron.New()
  15. spec := "*/5 * * * * ?"
  16. c.AddFunc(spec, func() {
  17. fmt.Println("--Execute job: " + time.Now().Format("2006-01-02 15:04:05"))
  18. //Do what you want to do
  19. }, "jobRunner")
  20. c.Start()
  21. done := make(chan bool)
  22. go forever()
  23. <-done // Block forever
  24.  
  25. }
  26.  
  27. func forever() {
  28. for {
  29. fmt.Printf("%v+\n", time.Now())
  30. time.Sleep(time.Second)
  31. }
  32. }
Add Comment
Please, Sign In to add comment