quick_start fixed

This commit is contained in:
yedongfu 2021-07-05 09:57:41 +08:00
parent 4e477afb5f
commit bffe8a7bbc
4 changed files with 10 additions and 6 deletions

View File

@ -12,7 +12,8 @@ import (
type M = map[string]interface{} type M = map[string]interface{}
func main() { func main() {
if os.Args[1] == "quick_start" { if len(os.Args) > 1 && (os.Args[1] == "quick_start" || os.Args[1] == "qs") {
dtmsvr.PopulateMysql()
dtmsvr.Main() dtmsvr.Main()
examples.StartMain() examples.StartMain()
for { for {

View File

@ -3,6 +3,7 @@ package dtmsvr
import ( import (
"math" "math"
"math/rand" "math/rand"
"runtime/debug"
"time" "time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -54,7 +55,7 @@ func lockOneTrans(expireIn time.Duration, status string) *TransGlobal {
func handlePanic() { func handlePanic() {
if err := recover(); err != nil { if err := recover(); err != nil {
logrus.Errorf("----panic %s handlered", err.(error).Error()) logrus.Errorf("\x1b[31m\n----panic %s handlered\x1b[0m\n%s", err.(error).Error(), string(debug.Stack()))
} }
} }

View File

@ -26,7 +26,7 @@ type TransGlobal struct {
} }
func (*TransGlobal) TableName() string { func (*TransGlobal) TableName() string {
return "trans_global" return "dtm.trans_global"
} }
type TransProcessor interface { type TransProcessor interface {
@ -73,7 +73,7 @@ type TransBranch struct {
} }
func (*TransBranch) TableName() string { func (*TransBranch) TableName() string {
return "trans_branch" return "dtm.trans_branch"
} }
func (t *TransBranch) changeStatus(db *common.DB, status string) *gorm.DB { func (t *TransBranch) changeStatus(db *common.DB, status string) *gorm.DB {

View File

@ -10,12 +10,15 @@ import (
"github.com/yedf/dtm/dtmcli" "github.com/yedf/dtm/dtmcli"
) )
// 启动命令go run app/main.go qs
// 事务参与者的服务地址 // 事务参与者的服务地址
const qsBusiApi = "/api/busi_start" const qsBusiApi = "/api/busi_start"
const qsBusiPort = 8082 const qsBusiPort = 8082
var qsBusi = fmt.Sprintf("http://localhost:%d%s", qsBusiPort, qsBusiApi) var qsBusi = fmt.Sprintf("http://localhost:%d%s", qsBusiPort, qsBusiApi)
// 被app/main.go调用启动服务并运行示例
func StartMain() { func StartMain() {
go qsStartSvr() go qsStartSvr()
qsFireRequest() qsFireRequest()
@ -23,9 +26,9 @@ func StartMain() {
} }
func qsStartSvr() { func qsStartSvr() {
logrus.Printf("quick start examples starting")
app := common.GetGinApp() app := common.GetGinApp()
qsAddRoute(app) qsAddRoute(app)
logrus.Printf("quick qs examples listening at %d", qsBusiPort)
app.Run(fmt.Sprintf(":%d", qsBusiPort)) app.Run(fmt.Sprintf(":%d", qsBusiPort))
} }
@ -55,5 +58,4 @@ func qsAddRoute(app *gin.Engine) {
app.POST(qsBusiApi+"/TransOutCompensate", common.WrapHandler(func(c *gin.Context) (interface{}, error) { app.POST(qsBusiApi+"/TransOutCompensate", common.WrapHandler(func(c *gin.Context) (interface{}, error) {
return M{"result": "SUCCESS"}, nil return M{"result": "SUCCESS"}, nil
})) }))
logrus.Printf("quick qs examples listening at %d", qsBusiPort)
} }