-
监控任务积压
# 总数 等待数 错误数
<select id="getMonitorList" parameterClass="map" resultClass="com.yb.domain.MonitorDO">
<![CDATA[
select sum(totalNum) as totalNum,
sum(waitNum) as waitNum,
sum(errNum) as errNum
from (
select 1 as totalNum,
case when isfinished = 0 and retrycount = 0 then 1 else 0 end as waitNum,
case when isfinished = 0 and retrycount > 0 or isfinished = 3 then 1 else 0 end as errNum
from $tableName$ with(nolock)
) t
]]>
</select>
<update id="batchResetFailTask" parameterClass="map">
<![CDATA[
update $tableName$ set retrycount = 0 , isFinished = 0
where isfinished = 0 and retrycount > 0 or isfinished = 3
]]>
</update>
-
load数 策略 和 重试策略
load取时候,只是load取5min前的。(状态机思想)
<!-- 解锁被领取任务 -->
<select id="loadTask" resultMap="TaskBO" parameterType="com.myshop.king.domain.query.TaskQuery">
SELECT <include refid="columns_all"></include>
from task${routeTableNameSuffix}
where (
( state = #{state} and exc_time <![CDATA[ < ]]> now() )
or
( state = #{state2} and exc_time <![CDATA[ < ]]> date_sub(now(), interval #{delay} minute) )
) # 两种情况(当前时间失败的任务, 5min前正在执行的任务)
# 判断状态时间
and yn = #{yn} and retry_count <![CDATA[ <= ]]> #{retryCount}
limit #{limit}
</select>
重试策略:更新状态时间(失败了,把执行时间往后plus指定时间)
RetryHourStrategy
int retryCount; 重试次数
int rate; 间隔时间(interval),速度
int excTime; 当前时间
DateUtil.plusMinutes(retryCount*rate, excTime);
自变量:retryCount。 rate常量。 y轴为时间。。