From 508a838f2f1b3f2f4a598768efc6423de2872949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Wed, 19 Mar 2025 20:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/config.yaml | 2 +- configs/config_test.yaml | 2 +- internal/service/consume.go | 2 +- internal/service/cron.go | 7 +++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/configs/config.yaml b/configs/config.yaml index c505118..fc40b93 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -83,7 +83,7 @@ cron: commandMap: orderNotice: isOpen: false #是否启动 true/false - command: "0 1 * * *" # 每天凌晨1点执行一次:0 2 * * * | "0 */10 * * *" #cron表达式,每10分钟执行一次 + command: "0 0 1 * * ?" # 每天凌晨1点执行一次 #配置日志 logs: diff --git a/configs/config_test.yaml b/configs/config_test.yaml index 1b1960b..dfbf049 100644 --- a/configs/config_test.yaml +++ b/configs/config_test.yaml @@ -80,7 +80,7 @@ cron: commandMap: orderNotice: isOpen: true #是否启动 true/false - command: "0 1 * * *" # 每天凌晨1点执行一次:0 2 * * * | "0 */10 * * *" #cron表达式,每10分钟执行一次 + command: "0 0 1 * * ?" # 每天凌晨1点执行一次 #配置日志 logs: diff --git a/internal/service/consume.go b/internal/service/consume.go index a2cd14c..17c7420 100644 --- a/internal/service/consume.go +++ b/internal/service/consume.go @@ -29,7 +29,7 @@ func (j *VoucherService) GetNotifyRetryConfig() *mq.ConsumerConfig { func (j *VoucherService) NotifyRetryConsumer(ctx context.Context, msg *mq.ConsumerMessage) error { shardingKey := msg.GetShardingKey() - if shardingKey == "" { + if len(shardingKey) == 0 { log.Error("notify retry 消费异常,获取 shardingKey 失败") return errors.New("orderNotify 消费异常,获取 orderNo 失败") } diff --git a/internal/service/cron.go b/internal/service/cron.go index febef44..add07ce 100644 --- a/internal/service/cron.go +++ b/internal/service/cron.go @@ -25,6 +25,13 @@ func (s *VoucherService) CronOrderNotice(ctx context.Context) error { return nil } + // 每五秒: */5 * * * * ? + // 每隔1分钟执行一次:"0 */1 * * * ?" + // 每天23点执行一次:"0 0 23 * * ?" + // 每天凌晨1点执行一次:"0 0 1 * * ?" + // 每月1号凌晨1点执行一次:"0 0 1 1 * ?" + // 在26分、29分、33分执行一次:"0 26,29,33 * * * ?" + // 每天的0点、13点、18点、21点都执行一次:"0 0 0,13,18,21 * * ?" return s.cron.AddFunc(c.Command, func() { s.OrderNotice(ctx)