Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提升失败任务日志的扫描效率 #3443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class JobFailMonitorHelper {
private static Logger logger = LoggerFactory.getLogger(JobFailMonitorHelper.class);

private static JobFailMonitorHelper instance = new JobFailMonitorHelper();
public static JobFailMonitorHelper getInstance(){
return instance;
Expand All @@ -33,12 +33,12 @@ public void start(){

@Override
public void run() {

Long lastFailLogId = null;
// monitor
while (!toStop) {
try {

List<Long> failLogIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findFailJobLogIds(1000);
List<Long> failLogIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findFailJobLogIds(lastFailLogId,1000);
if (failLogIds!=null && !failLogIds.isEmpty()) {
for (long failLogId: failLogIds) {

Expand Down Expand Up @@ -68,6 +68,7 @@ public void run() {
}

XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, -1, newAlarmStatus);
lastFailLogId = failLogId;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public int pageListCount(@Param("offset") int offset,
@Param("triggerTimeStart") Date triggerTimeStart,
@Param("triggerTimeEnd") Date triggerTimeEnd,
@Param("logStatus") int logStatus);

public XxlJobLog load(@Param("id") long id);

public long save(XxlJobLog xxlJobLog);

public int updateTriggerInfo(XxlJobLog xxlJobLog);

public int updateHandleInfo(XxlJobLog xxlJobLog);

public int delete(@Param("jobId") int jobId);

public Map<String, Object> findLogReport(@Param("from") Date from,
Expand All @@ -51,7 +51,7 @@ public List<Long> findClearLogIds(@Param("jobGroup") int jobGroup,
@Param("pagesize") int pagesize);
public int clearLog(@Param("logIds") List<Long> logIds);

public List<Long> findFailJobLogIds(@Param("pagesize") int pagesize);
public List<Long> findFailJobLogIds(@Param("lastJobLogId") Long lastJobLogId, @Param("pagesize") int pagesize);

public int updateAlarmStatus(@Param("logId") long logId,
@Param("oldAlarmStatus") int oldAlarmStatus,
Expand Down
29 changes: 16 additions & 13 deletions xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxl.job.admin.dao.XxlJobLogDao">

<resultMap id="XxlJobLog" type="com.xxl.job.admin.core.model.XxlJobLog" >
<result column="id" property="id" />

Expand All @@ -14,11 +14,11 @@
<result column="executor_param" property="executorParam" />
<result column="executor_sharding_param" property="executorShardingParam" />
<result column="executor_fail_retry_count" property="executorFailRetryCount" />

<result column="trigger_time" property="triggerTime" />
<result column="trigger_code" property="triggerCode" />
<result column="trigger_msg" property="triggerMsg" />

<result column="handle_time" property="handleTime" />
<result column="handle_code" property="handleCode" />
<result column="handle_msg" property="handleMsg" />
Expand All @@ -43,7 +43,7 @@
t.handle_msg,
t.alarm_status
</sql>

<select id="pageList" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_log AS t
Expand Down Expand Up @@ -77,7 +77,7 @@
ORDER BY t.trigger_time DESC
LIMIT #{offset}, #{pagesize}
</select>

<select id="pageListCount" resultType="int">
SELECT count(1)
FROM xxl_job_log AS t
Expand Down Expand Up @@ -109,14 +109,14 @@
</if>
</trim>
</select>

<select id="load" parameterType="java.lang.Long" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_log AS t
WHERE t.id = #{id}
</select>


<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO xxl_job_log (
`job_group`,
Expand All @@ -132,7 +132,7 @@
#{handleCode}
);
<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
SELECT LAST_INSERT_ID()
</selectKey>-->
</insert>

Expand All @@ -152,13 +152,13 @@

<update id="updateHandleInfo">
UPDATE xxl_job_log
SET
`handle_time`= #{handleTime},
SET
`handle_time`= #{handleTime},
`handle_code`= #{handleCode},
`handle_msg`= #{handleMsg}
WHERE `id`= #{id}
</update>

<delete id="delete" >
delete from xxl_job_log
WHERE job_id = #{jobId}
Expand Down Expand Up @@ -235,6 +235,9 @@
(handle_code = 200)
)
AND `alarm_status` = 0
<if test="lastJobLogId != null">
AND id <![CDATA[ > ]]> #{lastJobLogId}
</if>
ORDER BY id ASC
LIMIT #{pagesize}
</select>
Expand Down Expand Up @@ -270,4 +273,4 @@
)
-->

</mapper>
</mapper>