github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/cmd/jsjob/main.go (about) 1 ///go get github.com/angenalZZZ/gofunc/cmd/jsjob 2 ///go build -ldflags "-s -w" -o A:/test/cmd/jsjob/jsjob.exe ./cmd/jsjob 3 ///start A:/test/cmd/jsjob/jsjob.exe -t 4 ///start A:/test/cmd/jsjob/jsjob.exe -c jsjob.yaml 5 6 package main 7 8 import ( 9 "flag" 10 "os" 11 "runtime" 12 "syscall" 13 "time" 14 15 "github.com/angenalZZZ/gofunc/f" 16 ) 17 18 func main() { 19 // Your Arguments. 20 initArgs() 21 if len(os.Args) < 2 { 22 flag.Usage() 23 return 24 } 25 26 defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(runtime.NumCPU())) 27 28 // Check Arguments And Init Config. 29 checkArgs() 30 31 // New Client Connect. 32 natClientConnect() 33 34 // Init complete. 35 runInit() 36 37 // Run script test. 38 runTest() 39 40 // Hot update script file. 41 go func() { 42 ticket := time.NewTicker(1 * time.Second) 43 for range ticket.C { 44 isUpdated := false 45 for _, job := range jobList { 46 if job.FileIsMod() { 47 isUpdated = true 48 break 49 } 50 } 51 if isUpdated { 52 jobCron.Stop() 53 jobList = nil 54 runInit() 55 } 56 } 57 }() 58 59 // Pass the signals you want to end your application. 60 death := f.NewDeath(syscall.SIGINT, syscall.SIGTERM) 61 // When you want to block for shutdown signals. 62 death.WaitForDeathWithFunc(func() { 63 jobCron.Stop() 64 }) 65 }