dtmimp.DBTypeMysql:fmt.Sprintf(`next_cron_time < '%s' and status in ('prepared', 'aborting', 'submitted') limit 1`,nextCronTime),
dtmimp.DBTypePostgres:fmt.Sprintf(`id in (select id from trans_global where next_cron_time < '%s' and status in ('prepared', 'aborting', 'submitted') limit 1 )`,nextCronTime),
where:=fmt.Sprintf(`next_cron_time < '%s' and status in ('prepared', 'aborting', 'submitted')`,nextCronTime)
order:=map[string]string{
dtmimp.DBTypeMysql:`order by rand()`,
dtmimp.DBTypePostgres:`order by random()`,
}[conf.Store.Driver]
ssql:=fmt.Sprintf(`select count(1) from trans_global where %s`,where)
varcntint64
err:=db.ToSQLDB().QueryRow(ssql).Scan(&cnt)
dtmimp.PanicIf(err!=nil,err)
ifcnt==0{
ssql:=fmt.Sprintf(`select id from trans_global where %s %s limit 1`,where,order)
varidint64
err:=db.ToSQLDB().QueryRow(ssql).Scan(&id)
iferrors.Is(err,sql.ErrNoRows){
returnnil
}
dtmimp.PanicIf(err!=nil,err)
sql:=fmt.Sprintf(`UPDATE trans_global SET update_time='%s',next_cron_time='%s', owner='%s' WHERE %s`,
sql:=fmt.Sprintf(`UPDATE trans_global SET update_time='%s',next_cron_time='%s', owner='%s' WHERE id=%d and %s`,