perf: 限制回调失败最大重试次数为10
This commit is contained in:
@@ -33,3 +33,5 @@ const (
|
||||
UsdtXlayerDecimals = -6 // USDT Xlayer小数位数
|
||||
UsdtPolygonDecimals = -6 // USDT Polygon小数位数
|
||||
)
|
||||
|
||||
const NotifyMaxRetry = 10 // 最大重试次数
|
||||
|
||||
+7
-6
@@ -11,11 +11,11 @@ import (
|
||||
const (
|
||||
OrderNotifyStateSucc = 1 // 回调成功
|
||||
OrderNotifyStateFail = 0 // 回调失败
|
||||
OrderStatusCanceled = 4 // 订单取消
|
||||
|
||||
OrderStatusExpired = 3 // 订单过期
|
||||
OrderStatusSuccess = 2 // 订单成功
|
||||
OrderStatusWaiting = 1 // 等待支付
|
||||
OrderStatusCanceled = 4 // 订单取消
|
||||
OrderStatusExpired = 3 // 订单过期
|
||||
OrderStatusSuccess = 2 // 订单成功
|
||||
OrderStatusWaiting = 1 // 等待支付
|
||||
|
||||
OrderTradeTypeBscBnb = "bsc.bnb"
|
||||
OrderTradeTypeEthEth = "ethereum.eth"
|
||||
@@ -89,7 +89,7 @@ func (o *TradeOrders) MarkSuccess(blockNum int64, from, hash string, at time.Tim
|
||||
DB.Save(o)
|
||||
}
|
||||
|
||||
func (o *TradeOrders) OrderSetNotifyState(state int) error {
|
||||
func (o *TradeOrders) SetNotifyState(state int) error {
|
||||
o.NotifyNum += 1
|
||||
o.NotifyState = state
|
||||
|
||||
@@ -191,7 +191,8 @@ func GetOrderByStatus(Status int) []TradeOrders {
|
||||
|
||||
func GetNotifyFailedTradeOrders() ([]TradeOrders, error) {
|
||||
var orders []TradeOrders
|
||||
var res = DB.Where("status = ?", OrderStatusSuccess).Where("notify_num > ?", 0).
|
||||
var res = DB.Where("status = ?", OrderStatusSuccess).
|
||||
Where("notify_num <= ?", conf.NotifyMaxRetry).
|
||||
Where("notify_state = ?", OrderNotifyStateFail).Find(&orders)
|
||||
|
||||
return orders, res.Error
|
||||
|
||||
@@ -3,6 +3,7 @@ package notify
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/v03413/bepusdt/app"
|
||||
"github.com/v03413/bepusdt/app/bot"
|
||||
"github.com/v03413/bepusdt/app/conf"
|
||||
"github.com/v03413/bepusdt/app/help"
|
||||
@@ -77,7 +78,7 @@ func epay(order model.TradeOrders) {
|
||||
return
|
||||
}
|
||||
|
||||
err = order.OrderSetNotifyState(model.OrderNotifyStateSucc)
|
||||
err = order.SetNotifyState(model.OrderNotifyStateSucc)
|
||||
if err != nil {
|
||||
log.Error("订单标记通知成功错误:", err, order.OrderId)
|
||||
} else {
|
||||
@@ -124,6 +125,7 @@ func epusdt(order model.TradeOrders) {
|
||||
|
||||
postReq.Header.Set("Content-Type", "application/json")
|
||||
postReq.Header.Set("Powered-By", "https://github.com/v03413/bepusdt")
|
||||
postReq.Header.Set("User-Agent", "BEpusdt/"+app.Version)
|
||||
resp, err := client.Do(postReq)
|
||||
if err != nil {
|
||||
markNotifyFail(order, err.Error())
|
||||
@@ -151,7 +153,7 @@ func epusdt(order model.TradeOrders) {
|
||||
return
|
||||
}
|
||||
|
||||
err = order.OrderSetNotifyState(model.OrderNotifyStateSucc)
|
||||
err = order.SetNotifyState(model.OrderNotifyStateSucc)
|
||||
if err != nil {
|
||||
log.Error("订单标记通知成功错误:", err, order.OrderId)
|
||||
} else {
|
||||
@@ -212,16 +214,16 @@ func Bepusdt(order model.TradeOrders) {
|
||||
// 再次序列化
|
||||
jsonBody, err = json.Marshal(body)
|
||||
var client = http.Client{Timeout: time.Second * 5}
|
||||
var postReq, err2 = http.NewRequest("POST", o.NotifyUrl, strings.NewReader(string(jsonBody)))
|
||||
var req, err2 = http.NewRequest("POST", o.NotifyUrl, strings.NewReader(string(jsonBody)))
|
||||
if err2 != nil {
|
||||
db.Rollback()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
postReq.Header.Set("Content-Type", "application/json")
|
||||
postReq.Header.Set("Powered-By", "https://github.com/v03413/bepusdt")
|
||||
resp, err := client.Do(postReq)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Powered-By", "https://github.com/v03413/bepusdt")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
db.Rollback()
|
||||
|
||||
@@ -251,7 +253,7 @@ func Bepusdt(order model.TradeOrders) {
|
||||
}
|
||||
|
||||
func markNotifyFail(order model.TradeOrders, reason string) {
|
||||
log.Warn(fmt.Sprintf("订单回调失败(%v):%s %v", order.TradeId, reason, order.OrderSetNotifyState(model.OrderNotifyStateFail)))
|
||||
log.Warn(fmt.Sprintf("订单回调失败(%v):%s %v", order.TradeId, reason, order.SetNotifyState(model.OrderNotifyStateFail)))
|
||||
go func() {
|
||||
bot.SendNotifyFailed(order, reason)
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user