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) }