From d62d94d48c03943c650c6a751bed1dedd5e43ab4 Mon Sep 17 00:00:00 2001 From: AI Engineer Date: Mon, 22 Jun 2026 17:10:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(task):=20Config=20=E6=96=B0=E5=A2=9E=20Sup?= =?UTF-8?q?pressSuccessLog=20=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8A=91=E5=88=B6=E7=A9=BA=E8=BD=AE=E8=AF=A2=20success=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=88by=20AI=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: glm-5.1 --- CHANGELOG.md | 3 +++ README.md | 5 +++-- TEST.md | 8 ++++---- scheduler.go | 2 +- task.go | 5 +++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d8f22..fc318a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v1.5.5 - 2026-06-22 +- **新增**: `Config.SuppressSuccessLog` 字段,设为 true 时调度器跳过 success 日志,由任务函数自行按处理量汇报,避免空轮询日志噪音。 + ## v1.5.4 - 2026-06-21 - **依赖更新**: 升级依赖 `jsmod` 至 `v1.5.3`,`cast` 至 `v1.5.3`,`rand` 至 `v1.5.3`,`encoding` 至 `v1.5.4`,`shell` 至 `v1.5.3`,`safe` 至 `v1.5.2`,`id` 至 `v1.5.4`,`file` 至 `v1.5.5`,`config` 至 `v1.5.3`,`log` 至 `v1.5.8`。 diff --git a/README.md b/README.md index 35bd922..fc42d34 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,9 @@ task.Add("Report", "@every 1m", func(ctx context.Context) error { // ... return nil }, task.Config{ - Policy: task.PolicySkip, // 如果上次还没跑完,跳过本次 - Timeout: 5 * time.Second, // 单次执行超时 + Policy: task.PolicySkip, // 如果上次还没跑完,跳过本次 + Timeout: 5 * time.Second, // 单次执行超时 + SuppressSuccessLog: true, // 抑制默认 success 日志,由任务自行汇报 }) ``` diff --git a/TEST.md b/TEST.md index 62af86e..c76801f 100644 --- a/TEST.md +++ b/TEST.md @@ -1,7 +1,7 @@ # Test Report ## Environment -- **Date**: 2026-06-21 +- **Date**: 2026-06-22 - **Go Version**: go 1.25.0 - **OS**: darwin/amd64 @@ -19,9 +19,9 @@ ## Benchmarks | Benchmark | Iterations | ns/op | |-----------|------------|-------| -| BenchmarkTaskRegistration | 4059084 | 294.0 | -| BenchmarkTaskExecutionOverhead/Get | 51555876 | 19.81 | -| BenchmarkTaskExecutionOverhead/List | 9835569 | 106.5 | +| BenchmarkTaskRegistration | 3664093 | 318.1 | +| BenchmarkTaskExecutionOverhead/Get | 52381898 | 26.07 | +| BenchmarkTaskExecutionOverhead/List | 10123669 | 116.2 | ## Details diff --git a/scheduler.go b/scheduler.go index 9cf1087..99ff9d7 100644 --- a/scheduler.go +++ b/scheduler.go @@ -222,7 +222,7 @@ func (s *Scheduler) runTask(name string) { if err != nil { log.DefaultLogger.Error("task failed", "name", name, "err", err, "duration", duration.String()) - } else { + } else if !t.Config.SuppressSuccessLog { log.DefaultLogger.Info("task success", "name", name, "duration", duration.String()) } } diff --git a/task.go b/task.go index 7202266..c5fb87c 100644 --- a/task.go +++ b/task.go @@ -24,8 +24,9 @@ const ( // Config 任务配置 type Config struct { - Policy Policy `json:"policy"` - Timeout time.Duration `json:"timeout"` + Policy Policy `json:"policy"` + Timeout time.Duration `json:"timeout"` + SuppressSuccessLog bool `json:"suppressSuccessLog"` } // WithPolicy 创建指定策略的配置