fix: 修复待机控制器的 context 使用和忙循环问题

- interval: 添加 Sleep 避免默认分支的忙循环(CPU 100%)
- cron: 使用 context.Background() 确保定时任务完整执行,不受外部取消影响
- wait_card: 使用 context.Background() 确保读卡器监听完整执行

这些修复确保了关键操作能够完整运行,同时避免 CPU 资源浪费。
This commit is contained in:
2026-04-08 14:25:56 +08:00
parent bee3b98798
commit e31fca22c8
3 changed files with 9 additions and 4 deletions

View File

@@ -65,7 +65,8 @@ func Cron(rootRules []cronrange.Rule, cron string, play func(c context.Context)
case r := <-a:
if r {
if ok := m.TryLock(); ok {
ctx, cc := context.WithCancel(context.TODO())
// 使用独立 context 确保任务完整执行,不受外部取消影响
ctx, cc := context.WithCancel(context.Background())
cancel = cc
waitGroup.Add(1)
go func() {