Skip to content

Commit

Permalink
优化定时任务输出信息
Browse files Browse the repository at this point in the history
  • Loading branch information
ygxbnet committed Feb 10, 2025
1 parent 7ae3bd0 commit 546a38f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ttauto
go 1.23

require (
github.com/robfig/cron v1.2.0
github.com/robfig/cron/v3 v3.0.1
github.com/tidwall/gjson v1.18.0
)

Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/robfig/cron"
"github.com/robfig/cron/v3"
"github.com/tidwall/gjson"
"log"
"os"
Expand Down Expand Up @@ -57,14 +57,15 @@ func main() {
refreshTokensRegularly() // 定时刷新 token

// 定时任务,每天 3:00 定时执行一次
c := cron.New()
location, _ := time.LoadLocation("Asia/Shanghai")
c := cron.New(cron.WithLocation(location))
fmt.Println("【定时任务】已开启定时任务,每天 3:00 定时签到")
c.AddFunc("0 3 * * *", func() {
signInInfo, err := ttapi.SignIn(token)
if err != nil || gjson.Get(signInInfo, "errCode").Int() != 0 {
fmt.Println("【定时签到】签到失败:", signInInfo, err)
fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "【定时签到】签到失败:", signInInfo, err)
} else {
fmt.Println(time.Now().Format("2006-01-02 15:04:05"), " 【定时签到】签到成功!")
fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "【定时签到】签到成功!")
}
})
c.Start()
Expand Down Expand Up @@ -141,10 +142,10 @@ func refreshTokensRegularly() {

response, err := ttapi.RefreshToken(unionID)
if err != nil {
log.Panic("【定时任务】定时刷新 token 失败,请重新登陆\n", err)
fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "【定时任务】定时刷新 token 失败,请重新登陆\n", err)
}
token = gjson.Get(response, "data.token").String()
fmt.Println("【定时任务】定时刷新 token 成功")
fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "【定时任务】定时刷新 token 成功")
}
}()
}

0 comments on commit 546a38f

Please sign in to comment.