From 08bc3dd79d4ca03e3bc2b57be9ffba7e6f1ea048 Mon Sep 17 00:00:00 2001 From: yedongfu Date: Wed, 19 May 2021 11:29:50 +0800 Subject: [PATCH] add prepare cancel case --- dtmsvr/cron.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 dtmsvr/cron.go diff --git a/dtmsvr/cron.go b/dtmsvr/cron.go new file mode 100644 index 0000000..f99912d --- /dev/null +++ b/dtmsvr/cron.go @@ -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 = ?", "") + } +}