Monotor & 任务


  1. 监控任务积压
    # 总数 等待数  错误数 
    <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>


  1. 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轴为时间。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值