-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
38 lines (31 loc) · 628 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/ehsaniara/gointerlock"
)
func myJob() {
fmt.Println(time.Now(), " - called")
}
func main() {
cnx := context.Background()
var job = gointerlock.GoInterval{
LockVendor: gointerlock.RedisLock,
Name: "MyTestJob",
Interval: 2 * time.Second,
Arg: myJob,
RedisHost: "localhost:6379",
RedisPassword: "secret",
}
//test cron
go func() {
err := job.Run(cnx)
if err != nil {
log.Fatalf("Error: %s", err)
}
}()
//example: just run it for 10 second before application exits
time.Sleep(10 * time.Second)
}