This commit is contained in:
aozhiwei 2024-06-14 15:08:27 +08:00
parent 06b89e2aad
commit 467af263c0
2 changed files with 74 additions and 1 deletions

View File

@ -21,3 +21,9 @@ const (
ORDER_STATUS_FILLED = "FILLED"
ORDER_STATUS_EXPIRED = "EXPIRED"
)
const (
ORDER_UPDATE_EVENT = "imtbl_zkevm_order_updated"
TRADE_CREATED_EVENT = "imtbl_zkevm_trade_created"
ACTIVITY_SALE_EVENT = "imtbl_zkevm_activity_sale"
)

View File

@ -1,13 +1,80 @@
package task
import (
"q5"
"f5"
"main/constant"
"time"
)
type taskMgr struct {
}
func (this* taskMgr) Init() {
go this.syncOrderUpdatedEvent()
}
func (this* taskMgr) UnInit() {
}
func (this* taskMgr) syncOrderUpdatedEvent() {
var lastSyncIdx = this.getLastIdx(constant.ORDER_UPDATE_EVENT)
for true {
if lastSyncIdx < 0 {
lastSyncIdx = this.getLastIdx(constant.ORDER_UPDATE_EVENT)
if lastSyncIdx >= 0 {
continue
}
} else {
}
time.Sleep(time.Second * 3)
}
}
func (this* taskMgr) getLastIdx(eventName string) int64 {
var lastSyncIdx int64 = -1
f5.GetGoStyleDb().OrmSelectOne(
constant.BCEVENT_DB,
"t_webhook_process_last_idx",
[][]string{
{"event_name", eventName},
},
func (err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
lastSyncIdx = q5.ToInt64(ds.GetByName("last_idx"))
} else {
lastSyncIdx = 0
}
})
return lastSyncIdx
}
func (this* taskMgr) saveLastIdx(eventName string, lastIdx int64) bool {
var result bool = false
nowTime := f5.GetApp().GetRealSeconds()
f5.GetGoStyleDb().Upsert(
constant.BCEVENT_DB,
"t_webhook_process_last_idx",
[][]string{
{"event_name", eventName},
},
[][]string{
{"last_idx", q5.ToString(lastIdx)},
},
[][]string{
{"event_name", eventName},
{"last_idx", q5.ToString(lastIdx)},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
result = err == nil
})
return result
}