ai-week/cmd/main.go

43 lines
738 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"log"
"time"
"week/moonshot"
"week/qywechat"
"github.com/jasonlvhit/gocron"
)
var maxRetries = 3
func main() {
now := time.Now()
nowDate := now.Format("2006-01-02 15:04:05") + " " + now.Weekday().String()
log.Printf("等待执行定时任务中...当前时间是:%s", nowDate)
if maxRetries != 0 {
// 定义任务,每周五的五点执行
gocron.Every(1).Friday().At("17:00").Do(job)
// 开始定时任务
<-gocron.Start()
} else {
log.Fatalln("最大重试次数已到达3退出")
}
}
func job() {
err := moonshot.CreateExcel()
if err != nil {
job()
maxRetries--
}
repContent, err := moonshot.AiChat()
if err != nil {
job()
maxRetries--
}
qywechat.Send(repContent)
}