This is a creation in Article, where the information may have evolved or changed.
Site started using the WIN server System scheduled task, add Xx.bat, set the execution time
Content in Xx.bat:
C:\php\php.exe-q C:\WWW\api\script\AutoCancelOrder.php
This way is now working, and recently after watching Golang, I intend to use Golang to re-schedule the task.
Cron.go code below, go run requires go get-u github.com/jakecoffman/cron
Package Main
Import (
"FMT"
"Github.com/jakecoffman/cron"
"Io/ioutil"
"Net/http"
"Net/url"
"OS"
"Time"
)
Func Main () {
var C = cron. New ()
Spec: = "0 "
C.addfunc (Spec, func () {
Autotongji ()
}, "Autotongji")
spec = "*/15 * 9-17 * * ?"c.AddFunc(spec, func() { autoFddsign()}, "autoFddsign")c.Start()select {}
}
Daily data Statistics 0:30 executed once
Func Autotongji () {
LOG: = Fmt. Sprintf ("--tongji Execution time:%s, \ n", Times.) Now (). Format ("2006-01-02 15:04:05"))
Writelog (log)
}
The law of the Big Seal
Func autofddsign () {
Log1: = Fmt. Sprintf ("--fddsign Execution time:%s, \ n", Times.) Now (). Format ("2006-01-02 15:04:05"))
Writelog (LOG1)
}
Func request (Request string) (Rtn string) {
U, : = URL. Parse (Request)
Q: = U.query ()
Q.set ("token", "site@ @crontab")
U.rawquery = Q.encode ()
Reponse, : = http. Get (u.string ())
result, _: = Ioutil. ReadAll (reponse. Body)
Reponse. Body.close ()
RESULT_STR: = string (Result)
Return RESULT_STR
}
Write log
Func writelog (log string) {
LogDir: = "Log"
var path stringif os.IsPathSeparator('\\') { path = "\\"} else { path = "/"}dir, _ := os.Getwd()os.Mkdir(dir+path+logdir, os.ModePerm)file_path := dir + path + logdir + path + time.Now().Format("2006-01") + ".txt"_, err := os.Stat(file_path)if err != nil { f, _ := os.Create(file_path) defer f.Close()}f, _ := os.OpenFile(file_path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)f.WriteString(log)f.Close()
}
Func Checkerr (err error) {
If err! = Nil {
Fmt. Println (Err. Error ())
Panic (ERR)
}
}
Run Results View:
Tim20170602091555.jpg
Step two using NSSM to install and remove services
Install.bat installation Services, where absolute paths are used
NSSM Install Ddauto F:\golang\src\cron.exe
NSSM Start Ddauto
Delete.bat: Deleting a service
NSSM Stop Ddauto
NSSM Remove Ddauto
The code is a little distorted. Look at this ...
As for spec = "/15 9-17 ?" Time settings, you can refer to the use of the Linux crontab, Golang cron more than crontab units per second unit settings