104 lines
4.9 KiB
XML
104 lines
4.9 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<!DOCTYPE mapper
|
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="com.ruoyi.out.dispatch.mapper.WcsJobDispatchMapper">
|
|
|
|
<resultMap type="com.ruoyi.out.dispatch.domain.WcsJobDispatch" id="WcsJobDispatchResult">
|
|
<id property="jobId" column="job_id" />
|
|
<result property="dispatchStatus" column="dispatch_status" />
|
|
<result property="autoRetryCount" column="auto_retry_count" />
|
|
<result property="manualRetryCount" column="manual_retry_count" />
|
|
<result property="lastError" column="last_error" />
|
|
<result property="lastAttemptTime" column="last_attempt_time" />
|
|
<result property="nextRetryTime" column="next_retry_time" />
|
|
<result property="successTime" column="success_time" />
|
|
<result property="versionNo" column="version_no" />
|
|
<result property="createTime" column="create_time" />
|
|
<result property="updateTime" column="update_time" />
|
|
</resultMap>
|
|
|
|
<insert id="insertIfAbsent" parameterType="String">
|
|
if not exists (select 1 from wcs_job_dispatch with (updlock, holdlock) where job_id = #{jobId})
|
|
begin
|
|
insert into wcs_job_dispatch
|
|
(job_id, dispatch_status, auto_retry_count, manual_retry_count, version_no, create_time, update_time)
|
|
values
|
|
(#{jobId}, 'PENDING', 0, 0, 0, getdate(), getdate())
|
|
end
|
|
</insert>
|
|
|
|
<select id="selectByJobId" parameterType="String" resultMap="WcsJobDispatchResult">
|
|
select job_id, dispatch_status, auto_retry_count, manual_retry_count, last_error,
|
|
last_attempt_time, next_retry_time, success_time, version_no, create_time, update_time
|
|
from wcs_job_dispatch
|
|
where job_id = #{jobId}
|
|
</select>
|
|
|
|
<select id="selectRetryCandidates" resultMap="WcsJobDispatchResult">
|
|
select top (#{limit}) job_id, dispatch_status, auto_retry_count, manual_retry_count, last_error,
|
|
last_attempt_time, next_retry_time, success_time, version_no, create_time, update_time
|
|
from wcs_job_dispatch with (readpast)
|
|
where (dispatch_status = 'RETRY_WAIT'
|
|
and auto_retry_count < 5
|
|
and (next_retry_time is null or next_retry_time <= #{now}))
|
|
or dispatch_status = 'BLOCKED'
|
|
or (dispatch_status = 'SENDING'
|
|
and last_attempt_time <= dateadd(minute, -5, #{now}))
|
|
order by create_time, job_id
|
|
</select>
|
|
|
|
<update id="claimForSend" parameterType="map">
|
|
update wcs_job_dispatch
|
|
set dispatch_status = 'SENDING',
|
|
auto_retry_count = auto_retry_count + case when #{trigger} = 'AUTO_RETRY' then 1 else 0 end,
|
|
manual_retry_count = manual_retry_count + case when #{trigger} = 'MANUAL' then 1 else 0 end,
|
|
last_attempt_time = #{attemptTime},
|
|
next_retry_time = null,
|
|
update_time = #{attemptTime},
|
|
version_no = version_no + 1
|
|
where job_id = #{jobId}
|
|
and version_no = #{versionNo}
|
|
and dispatch_status in ('PENDING', 'BLOCKED', 'RETRY_WAIT', 'EXHAUSTED', 'SENDING')
|
|
and (dispatch_status != 'SENDING'
|
|
or last_attempt_time <= dateadd(minute, -5, #{attemptTime}))
|
|
and (#{trigger} != 'AUTO_RETRY' or auto_retry_count < 5)
|
|
</update>
|
|
|
|
<update id="markBlocked" parameterType="map">
|
|
update wcs_job_dispatch
|
|
set dispatch_status = 'BLOCKED', last_error = #{lastError}, next_retry_time = #{nextRetryTime},
|
|
update_time = #{updateTime}, version_no = version_no + 1
|
|
where job_id = #{jobId}
|
|
and version_no = #{versionNo}
|
|
and dispatch_status != 'SUCCESS'
|
|
</update>
|
|
|
|
<update id="markRetryWait" parameterType="map">
|
|
update wcs_job_dispatch
|
|
set dispatch_status = 'RETRY_WAIT', last_error = #{lastError}, next_retry_time = #{nextRetryTime},
|
|
update_time = #{updateTime}, version_no = version_no + 1
|
|
where job_id = #{jobId}
|
|
and version_no = #{versionNo}
|
|
and dispatch_status = 'SENDING'
|
|
</update>
|
|
|
|
<update id="markSuccess" parameterType="map">
|
|
update wcs_job_dispatch
|
|
set dispatch_status = 'SUCCESS', last_error = null, next_retry_time = null,
|
|
success_time = #{successTime}, update_time = #{successTime}, version_no = version_no + 1
|
|
where job_id = #{jobId}
|
|
and version_no = #{versionNo}
|
|
and dispatch_status = 'SENDING'
|
|
</update>
|
|
|
|
<update id="markExhausted" parameterType="map">
|
|
update wcs_job_dispatch
|
|
set dispatch_status = 'EXHAUSTED', last_error = #{lastError}, next_retry_time = null,
|
|
update_time = #{updateTime}, version_no = version_no + 1
|
|
where job_id = #{jobId}
|
|
and version_no = #{versionNo}
|
|
and dispatch_status in ('SENDING', 'BLOCKED', 'RETRY_WAIT')
|
|
</update>
|
|
</mapper>
|