- elm use routine pool.

This commit is contained in:
gazebo
2018-06-28 12:38:45 +08:00
parent b756990cee
commit 718c54b507
3 changed files with 19 additions and 7 deletions

View File

@@ -19,18 +19,24 @@ var (
type OrderController struct {
}
func (o *OrderController) OrderMessage(msg *elmapi.CallbackMsg) *elmapi.CallbackResponse {
func (o *OrderController) OrderMessage(msg *elmapi.CallbackMsg) (retVal *elmapi.CallbackResponse) {
var innerMsg map[string]interface{}
err := utils.UnmarshalUseNumber([]byte(msg.Message), &innerMsg)
if err != nil {
return errResponseDataError
}
if msg.Type == elmapi.MsgTypeOrderValid {
return o.NewOrder(msg, innerMsg["id"].(string))
} else if msg.Type >= elmapi.MsgTypeMerchantValid && msg.Type <= elmapi.MsgTypeOrderFinished {
return o.OrderStatusChanged(msg, innerMsg["orderId"].(string))
}
return elmapi.SuccessResponse
retVal = elmapi.SuccessResponse
orderID := innerMsg["orderId"].(string)
globals2.RoutinePool.CallFun(func() {
if msg.Type == elmapi.MsgTypeOrderValid {
retVal = o.NewOrder(msg, orderID)
} else if msg.Type >= elmapi.MsgTypeMerchantValid && msg.Type <= elmapi.MsgTypeOrderFinished {
retVal = o.OrderStatusChanged(msg, orderID)
}
}, orderID)
return retVal
}
func (o *OrderController) NewOrder(msg *elmapi.CallbackMsg, orderId string) *elmapi.CallbackResponse {

View File

@@ -7,6 +7,8 @@ EnableDocs = true
RouterCaseSensitive = false
filelinenum = true
routinePoolSize = 1000
dadaAppKey = "dada9623324449cd250"
dadaAppSecret = "30c2abbfe8a8780ad5aace46300c64b9"

View File

@@ -7,6 +7,7 @@ import (
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/routinepool"
elmmodels "git.rosy.net.cn/jx-callback/business/elm/models"
"git.rosy.net.cn/jx-callback/business/freshfood"
jdmodels "git.rosy.net.cn/jx-callback/business/jd/models"
@@ -22,6 +23,7 @@ const (
)
var (
RoutinePool *routinepool.Pool
FreshFoodAPI *freshfood.FreshFoodAPI
Jdapi *jdapi.API
@@ -33,6 +35,8 @@ var (
func init() {
initDB()
routinePoolSize := beego.AppConfig.DefaultInt("routinePoolSize", 0)
RoutinePool = routinepool.New(routinePoolSize, routinePoolSize)
FreshFoodAPI = freshfood.NewFreshFoodAPI(beego.AppConfig.String("freshFoodServerURL"))
Jdapi = jdapi.New(beego.AppConfig.String("jdToken"), beego.AppConfig.String("jdAppKey"), beego.AppConfig.String("jdSecret"))
initElm()