orderNotice定时任务

This commit is contained in:
李子铭 2025-03-18 20:24:07 +08:00
parent 0700044a0e
commit 8a64a2b32e
2 changed files with 22 additions and 0 deletions

View File

@ -8,6 +8,24 @@ import (
func (s *VoucherService) CronNotice(ctx context.Context) error { func (s *VoucherService) CronNotice(ctx context.Context) error {
c, ok := s.bc.Cron.CommandMap["orderNotice"]
if !ok {
log.Warn("orderNotice定时任务未开启")
return nil
}
return s.cron.AddFunc(c.Command, func() {
if err := s.Notice(ctx); err != nil {
log.Errorf("orderNotice定时任务执行发生错误: %v", err)
}
})
}
func (s *VoucherService) Notice(ctx context.Context) error {
start := time.Now() start := time.Now()
if err := s.VoucherBiz.Notice(ctx); err != nil { if err := s.VoucherBiz.Notice(ctx); err != nil {

View File

@ -1,6 +1,7 @@
package service package service
import ( import (
"github.com/robfig/cron"
"voucher/internal/biz" "voucher/internal/biz"
"voucher/internal/biz/mixrepos" "voucher/internal/biz/mixrepos"
"voucher/internal/biz/wechatrepo" "voucher/internal/biz/wechatrepo"
@ -9,6 +10,7 @@ import (
type VoucherService struct { type VoucherService struct {
bc *conf.Bootstrap bc *conf.Bootstrap
cron *cron.Cron
VoucherBiz *biz.VoucherBiz VoucherBiz *biz.VoucherBiz
CmbMixRepo mixrepos.CmbMixRepo CmbMixRepo mixrepos.CmbMixRepo
WechatCpnRepo wechatrepo.WechatCpnRepo WechatCpnRepo wechatrepo.WechatCpnRepo
@ -16,12 +18,14 @@ type VoucherService struct {
func NewVoucherService( func NewVoucherService(
bc *conf.Bootstrap, bc *conf.Bootstrap,
cron *cron.Cron,
VoucherBiz *biz.VoucherBiz, VoucherBiz *biz.VoucherBiz,
CmbMixRepo mixrepos.CmbMixRepo, CmbMixRepo mixrepos.CmbMixRepo,
WechatCpnRepo wechatrepo.WechatCpnRepo, WechatCpnRepo wechatrepo.WechatCpnRepo,
) *VoucherService { ) *VoucherService {
return &VoucherService{ return &VoucherService{
bc: bc, bc: bc,
cron: cron,
VoucherBiz: VoucherBiz, VoucherBiz: VoucherBiz,
CmbMixRepo: CmbMixRepo, CmbMixRepo: CmbMixRepo,
WechatCpnRepo: WechatCpnRepo, WechatCpnRepo: WechatCpnRepo,