File tree Expand file tree Collapse file tree 4 files changed +58
-0
lines changed
Expand file tree Collapse file tree 4 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments