Created
January 22, 2019 19:11
-
-
Save parzibyte/4c44a238528efcf17c52f42917923085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
Ejemplo simple de cómo usar cron en Go | |
@author parzibyte | |
*/ | |
import ( | |
"fmt" | |
"github.com/robfig/cron" | |
) | |
func main() { | |
// Crear un cron | |
c := cron.New() | |
// Por cierto, al terminar lo detenemos | |
// https://parzibyte.me/blog/2018/12/18/defer-go/ | |
defer c.Stop() | |
// Agregarle funciones... | |
// Ejecutar cada segundo toda la vida | |
c.AddFunc("* * * * * *", func() { | |
fmt.Println("Me imprimo cada segundo") | |
}) | |
// Comenzar | |
c.Start() | |
// Lo siguiente es únicamente para pausar el programa y no tiene nada | |
// que ver con cron o el ejemplo, recuerda que | |
// el programa se detiene con Ctrl + C | |
select {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment