81 lines
1.5 KiB
Go
81 lines
1.5 KiB
Go
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
|
|
}
|