Merge branch 'main' into clean_beep
# Conflicts: # internal/routes/wait.go
This commit is contained in:
18
internal/middleware/cache.go
Normal file
18
internal/middleware/cache.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"game-driver/config"
|
||||
"game-driver/leaf"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Cache 缓存中间件
|
||||
func Cache(cache config.Cache) leaf.HandlerFunc {
|
||||
return func(c *leaf.Context) {
|
||||
err := cache.Set(c.Publish)
|
||||
if err != nil {
|
||||
zap.S().Errorln("缓存数据失败: ", err)
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
15
internal/middleware/pause_wait.go
Normal file
15
internal/middleware/pause_wait.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"game-driver/internal/common"
|
||||
"game-driver/leaf"
|
||||
)
|
||||
|
||||
func PauseWait(ctrl *common.CtrlWait) leaf.HandlerFunc {
|
||||
return func(c *leaf.Context) {
|
||||
ctrl.Pause()
|
||||
defer ctrl.Resume()
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,10 @@ func SoundStart() leaf.HandlerFunc {
|
||||
|
||||
defer func() {
|
||||
switch leaf.Value[leaf.EndType](c, leaf.EndKey) {
|
||||
case leaf.EndTimer:
|
||||
case leaf.End:
|
||||
tts.DefaultTTS.Sound(pm.TTS.End)
|
||||
case leaf.EndTimeout:
|
||||
tts.DefaultTTS.Sound(pm.TTS.Timeout)
|
||||
case leaf.EndStop:
|
||||
tts.DefaultTTS.Sound(pm.TTS.Stop)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"game-driver/internal/common"
|
||||
"game-driver/leaf"
|
||||
"go.uber.org/zap"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// EmergencyStop 紧急停止中间件
|
||||
@@ -12,14 +13,21 @@ func EmergencyStop(stopper common.Stopper) leaf.HandlerFunc {
|
||||
cancel := leaf.WithCancel(c)
|
||||
defer stopper.Reset()
|
||||
|
||||
zap.S().Infoln("监听停止信号")
|
||||
defer zap.S().Infoln("结束停止信号监听")
|
||||
|
||||
// 等待组
|
||||
var wait sync.WaitGroup
|
||||
defer wait.Wait()
|
||||
|
||||
// 结束信号通道
|
||||
a := make(chan struct{})
|
||||
// 发送结束信号
|
||||
defer close(a)
|
||||
|
||||
zap.S().Infoln("监听停止信号")
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
defer zap.S().Infoln("结束停止信号监听")
|
||||
defer wait.Done()
|
||||
|
||||
select {
|
||||
case <-a:
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TickerAction 定时器动作,用于在指定时间点执行打印和语音播报
|
||||
func TickerAction() leaf.HandlerFunc {
|
||||
return func(c *leaf.Context) {
|
||||
pm := leaf.Value[*schema.PlayModal](c, PayloadJSONKey)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TimeoutOver 定时器中间件,用于定时触发屏幕打印和语音播报。 t 是语音播报实例
|
||||
// TimeoutOver 超时停止
|
||||
func TimeoutOver(maxTimeout int) leaf.HandlerFunc {
|
||||
return func(c *leaf.Context) {
|
||||
pm := leaf.Value[*schema.PlayModal](c, PayloadJSONKey)
|
||||
@@ -46,7 +46,7 @@ func TimeoutOver(maxTimeout int) leaf.HandlerFunc {
|
||||
{
|
||||
zap.S().Infoln("超时 Timer 触发")
|
||||
cancel()
|
||||
leaf.WithValue[leaf.EndType](c, leaf.EndKey, leaf.EndTimer)
|
||||
leaf.WithValue[leaf.EndType](c, leaf.EndKey, leaf.EndTimeout)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -12,7 +12,7 @@ func Unique(stopper common.Stopper) leaf.HandlerFunc {
|
||||
var lock sync.Mutex
|
||||
return func(c *leaf.Context) {
|
||||
if !lock.TryLock() {
|
||||
zap.S().Infoln("尝试加锁失败,执行停止任务")
|
||||
zap.S().Infoln("停止之前的任务,再尝试加锁")
|
||||
stopper.Stop()
|
||||
lock.Lock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user