42 lines
914 B
Go
42 lines
914 B
Go
package stake_settle
|
|
|
|
import (
|
|
"context"
|
|
"github.com/robfig/cron/v3"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"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 c.svcCtx.Config.NftTaskCron.SettleSpec
|
|
}
|
|
|
|
func (c *Cron) Run() {
|
|
start, end, err := c.svcCtx.ConfigModel.GetNftStakeTaskOpenDate(c.ctx)
|
|
if err != nil {
|
|
logx.Errorw("get nft stake task open date failed", logx.Field("err", err))
|
|
return
|
|
}
|
|
end = end.AddDate(0, 0, 1).Add(-time.Second)
|
|
now := time.Now()
|
|
if now.Before(start) || now.After(end) {
|
|
logx.Debugw("now is not in the date range", logx.Field("now", now), logx.Field("start", start), logx.Field("end", end))
|
|
return
|
|
}
|
|
|
|
logx.Debugw("run settle cron task")
|
|
}
|