orderNotice定时任务
This commit is contained in:
parent
0700044a0e
commit
8a64a2b32e
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue