tribally report
This commit is contained in:
41
internal/job/tribally_report/cron.go
Normal file
41
internal/job/tribally_report/cron.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package tribally_report
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"nova_task/internal/consts"
|
||||
"nova_task/internal/svc"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Cron struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCron(ctx context.Context, svcCtx *svc.ServiceContext) cron.Job {
|
||||
return &Cron{ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (c *Cron) Spec() string {
|
||||
return "@every 30s"
|
||||
}
|
||||
|
||||
func (c *Cron) Run() {
|
||||
tr, err := c.svcCtx.GlobalDataModel.GetValue(c.ctx, consts.TriballyReportTime)
|
||||
if err != nil {
|
||||
logx.Errorw("get tribally report time failed", logx.Field("err", err))
|
||||
return
|
||||
}
|
||||
var updateTime time.Time
|
||||
if tr != "" {
|
||||
updateTime, err = time.Parse(time.DateTime, tr)
|
||||
if err != nil {
|
||||
logx.Errorw("parse tribally report time failed", logx.Field("err", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.svcCtx.TriballyUserModel.FindUpdateTriballyUsers(c.ctx, updateTime, 100)
|
||||
}
|
||||
Reference in New Issue
Block a user