update sleep CronTime

This commit is contained in:
yedongfu 2021-06-05 16:16:06 +08:00
parent 3d32a9a56a
commit 08994c8c42
4 changed files with 7 additions and 5 deletions

View File

@ -14,7 +14,7 @@ type M = map[string]interface{}
func main() {
if len(os.Args) == 1 { // 默认情况下展示saga例子
dtmsvr.PopulateMysql()
go dtmsvr.StartSvr()
go dtmsvr.Main()
go examples.SagaStartSvr()
time.Sleep(100 * time.Millisecond)
examples.SagaFireRequest()
@ -23,7 +23,7 @@ func main() {
} else if os.Args[1] == "all" { // 运行所有示例
dtmsvr.PopulateMysql()
examples.PopulateMysql()
go dtmsvr.StartSvr()
go dtmsvr.Main()
go examples.SagaStartSvr()
go examples.TccStartSvr()
go examples.XaStartSvr()

View File

@ -1,8 +1,8 @@
package dtmsvr
type dtmsvrConfig struct {
PreparedExpire int64 // 单位秒处于prepared中的任务过了这个时间查询结果还是PENDING的话则会被cancel
JobCronInterval int64 // 单位秒 当事务等待这个时间之后还没有变化则进行一轮处理包括prepared中的任务和commited的任务
PreparedExpire uint64 // 单位秒处于prepared中的任务过了这个时间查询结果还是PENDING的话则会被cancel
JobCronInterval uint64 // 单位秒 当事务等待这个时间之后还没有变化则进行一轮处理包括prepared中的任务和commited的任务
Mysql map[string]string
}

View File

@ -61,6 +61,6 @@ func handlePanic() {
func sleepCronTime() {
delta := math.Min(3, float64(config.JobCronInterval))
interval := time.Duration(rand.Float64() * delta * float64(time.Second))
interval := time.Duration((float64(config.JobCronInterval) - rand.Float64()*delta) * float64(time.Second))
time.Sleep(interval)
}

View File

@ -12,6 +12,8 @@ var dtmsvrPort = 8080
func Main() {
go StartSvr()
go CronCommitted()
go CronPrepared()
}
func StartSvr() {