add prepare cancel case
This commit is contained in:
parent
60d8272cd4
commit
08bc3dd79d
24
dtmsvr/cron.go
Normal file
24
dtmsvr/cron.go
Normal file
@ -0,0 +1,24 @@
|
||||
package dtmsvr
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yedf/dtm/common"
|
||||
)
|
||||
|
||||
func CronPreparedOne(expire time.Duration) {
|
||||
db := DbGet()
|
||||
sm := SagaModel{}
|
||||
dbr := db.Model(&sm).Where("update_time > date_add(now(), interval ? second)", int(expire/time.Second)).Where("status = ?", "prepared").First(&sm)
|
||||
common.PanicIfError(dbr.Error)
|
||||
resp, err := common.RestyClient.R().SetQueryParam("gid", sm.Gid).Get(sm.TransQuery)
|
||||
common.PanicIfError(err)
|
||||
body := resp.String()
|
||||
if strings.Contains(body, "FAIL") {
|
||||
dbr = db.Model(&sm).Where("status = ?", "prepared").Update("status", "canceled")
|
||||
common.PanicIfError(dbr.Error)
|
||||
} else if strings.Contains(body, "SUCESS") {
|
||||
dbr = db.Model(&sm).Where("status = ?", "")
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user