Skip to content

Commit c85514c

Browse files
example
1 parent 5d27187 commit c85514c

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

_example/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.PHONY: fmt check-fmt lint vet test
2+
3+
run:
4+
rerun -watch . .. -run sh -c 'go run .'
5+
6+
update:
7+
go get github.com/golang-cz/looper@latest

_example/go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module testslog
2+
3+
go 1.22
4+
5+
toolchain go1.24.2
6+
7+
replace github.com/golang-cz/looper => ../
8+
9+
require github.com/golang-cz/looper v0.0.0-00010101000000-000000000000

_example/go.sum

Whitespace-only changes.

_example/main.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"time"
7+
8+
"github.com/golang-cz/looper"
9+
)
10+
11+
func main() {
12+
l := looper.New(nil)
13+
14+
j := &looper.Job{
15+
JobFn: job,
16+
Name: "jj",
17+
Timeout: 10 * time.Second,
18+
WaitAfterSuccess: 4 * time.Second,
19+
WaitAfterError: 4 * time.Second,
20+
Active: true,
21+
}
22+
23+
ctx := context.Background()
24+
25+
if err := l.AddJob(ctx, j); err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
l.Start()
30+
31+
select {}
32+
}
33+
34+
func job(ctx context.Context) error {
35+
log.Println("job start")
36+
37+
time.Sleep(2 * time.Second)
38+
39+
log.Println("job end")
40+
41+
return nil
42+
}

0 commit comments

Comments
 (0)