1
This commit is contained in:
parent
0717a7c7f1
commit
448a111764
94
server/backtask/task/refresh_meta.go
Normal file
94
server/backtask/task/refresh_meta.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"q5"
|
||||||
|
"f5"
|
||||||
|
"fmt"
|
||||||
|
"jccommon"
|
||||||
|
"main/constant"
|
||||||
|
"main/service"
|
||||||
|
"math/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
type refreshMeta struct {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this* refreshMeta) init() {
|
||||||
|
go this.process()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this* refreshMeta) unInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this* refreshMeta) process() {
|
||||||
|
f5.GetGoStyleDb().LoopLoad(
|
||||||
|
constant.BCNFT_DB,
|
||||||
|
"refreshMeta",
|
||||||
|
"t_order",
|
||||||
|
func () int64 {
|
||||||
|
return 60 + q5.ToInt64(rand.Intn(3))
|
||||||
|
},
|
||||||
|
func (lastIdx int64) string {
|
||||||
|
sql := fmt.Sprintf(`
|
||||||
|
SELECT * FROM t_order WHERE idx > %d AND status = ? LIMIT 100`,
|
||||||
|
lastIdx,
|
||||||
|
)
|
||||||
|
return sql
|
||||||
|
},
|
||||||
|
[]string{
|
||||||
|
jccommon.ORDER_STATUS_ACTIVE,
|
||||||
|
},
|
||||||
|
func () int64 {
|
||||||
|
return 3
|
||||||
|
},
|
||||||
|
func () int64 {
|
||||||
|
return 60 + q5.ToInt64(rand.Intn(3))
|
||||||
|
},
|
||||||
|
this.repairPrice)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this* refreshMeta) repairPrice(ds *f5.DataSet) bool {
|
||||||
|
if service.BcCurrency.GetLastRefreshOkTime() + 3600 * 2 < f5.GetApp().GetRealSeconds() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
dbIdx := ds.GetByName("idx")
|
||||||
|
eventId := ds.GetByName("event_id")
|
||||||
|
srcPriceAmount := ds.GetByName("src_price_amount")
|
||||||
|
srcPriceContractAddress := ds.GetByName("src_price_contract_address")
|
||||||
|
srcPriceItemType := ds.GetByName("src_price_item_type")
|
||||||
|
if srcPriceAmount == "" {
|
||||||
|
p := new(jccommon.OrderUpdatedEvent)
|
||||||
|
err := q5.DecodeJson(ds.GetByName("event_data"), &p)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
srcPriceAmount = p.Data.Buy[0].Amount
|
||||||
|
srcPriceContractAddress = p.Data.Buy[0].ContractAddress
|
||||||
|
srcPriceItemType = p.Data.Buy[0].ItemType
|
||||||
|
}
|
||||||
|
srcPriceExchangeRate, price := service.BcCurrency.ExchangeUSD(
|
||||||
|
srcPriceAmount, srcPriceItemType, srcPriceContractAddress)
|
||||||
|
updateFields := [][]string{
|
||||||
|
{"src_price_amount", srcPriceAmount},
|
||||||
|
{"src_price_contract_address", srcPriceContractAddress},
|
||||||
|
{"src_price_item_type", srcPriceItemType},
|
||||||
|
{"price", price},
|
||||||
|
{"price_len", q5.ToString(len(price))},
|
||||||
|
{"src_price_exchange_rate", q5.ToString(srcPriceExchangeRate)},
|
||||||
|
}
|
||||||
|
f5.GetGoStyleDb().Update(
|
||||||
|
constant.BCNFT_DB,
|
||||||
|
"t_order",
|
||||||
|
[][]string{
|
||||||
|
{"idx", q5.ToString(dbIdx)},
|
||||||
|
{"event_id", eventId},
|
||||||
|
},
|
||||||
|
updateFields,
|
||||||
|
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
@ -16,6 +16,7 @@ type taskMgr struct {
|
|||||||
openGoldLock sync.Mutex
|
openGoldLock sync.Mutex
|
||||||
sysMail
|
sysMail
|
||||||
repairOrder
|
repairOrder
|
||||||
|
refreshMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *taskMgr) Init() {
|
func (this *taskMgr) Init() {
|
||||||
@ -27,9 +28,11 @@ func (this *taskMgr) Init() {
|
|||||||
this.repairNft.init()
|
this.repairNft.init()
|
||||||
this.sysMail.init()
|
this.sysMail.init()
|
||||||
this.repairOrder.init()
|
this.repairOrder.init()
|
||||||
|
this.refreshMeta.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *taskMgr) UnInit() {
|
func (this *taskMgr) UnInit() {
|
||||||
|
this.refreshMeta.unInit()
|
||||||
this.repairOrder.unInit()
|
this.repairOrder.unInit()
|
||||||
this.sysMail.unInit()
|
this.sysMail.unInit()
|
||||||
this.repairNft.unInit()
|
this.repairNft.unInit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user