com.snow.auto_monitor/app/services/transfersys/transfersys_timeout.go

40 lines
889 B
Go
Raw Normal View History

2024-08-03 00:38:50 +08:00
package transfersys
import (
"context"
"fmt"
"strconv"
"time"
models "com.snow.auto_monitor/app/models/orders"
"github.com/qit-team/snow-core/log/logger"
)
func DoTimeout() {
fmt.Println("开始执行周期任务DoTimeout")
// 创建一个新的Ticker每3秒钟触发一次
ticker := time.NewTicker(3 * time.Second)
defer ticker.Stop() // 在函数结束时停止Ticker
for range ticker.C {
res, err := models.GetInstance().GetTimeoutOrder(10)
if err != nil {
fmt.Println(err.Error())
continue
}
for i := 0; i < len(res); i++ {
models.GetInstance().CancelOrder(res[i].Id)
err = AddCallback(strconv.Itoa(int(res[i].Id)))
if err != nil {
logger.Error(context.TODO(), "order timeout", err)
continue
}
logger.Info(context.TODO(), "order timeout", "orderId: "+strconv.FormatInt(res[i].Id, 10))
}
}
}
func init() {
2024-09-10 18:38:06 +08:00
go DoTimeout()
2024-08-03 00:38:50 +08:00
}