feiyu02
2023-11-08 b2a0cb67e3a422c6cfae1845a499edd6f4b32e74
1. 调整了定时任务的部分代码结构
已修改1个文件
已删除5个文件
已添加4个文件
306 ■■■■■ 文件已修改
src/main/java/com/flightfeather/monitor/scheduledtasks/DustAnalysisTask.kt 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/DustDailyStatisticAnalysisTask.kt 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/DustExceptionAnalysisTask.kt 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/DustMonthlyStatisticAnalysisTask.kt 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/TaskController.kt 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/BaseDustTimingTask.kt 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/DustDailyAnalysisTask.kt 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/DustExceptionAnalysisTask.kt 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/DustMonthlyAnalysisTask.kt 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/flightfeather/monitor/scheduledtasks/DustAnalysisTaskTest.kt 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/scheduledtasks/DustAnalysisTask.kt
ÎļþÒÑɾ³ý
src/main/java/com/flightfeather/monitor/scheduledtasks/DustDailyStatisticAnalysisTask.kt
ÎļþÒÑɾ³ý
src/main/java/com/flightfeather/monitor/scheduledtasks/DustExceptionAnalysisTask.kt
ÎļþÒÑɾ³ý
src/main/java/com/flightfeather/monitor/scheduledtasks/DustMonthlyStatisticAnalysisTask.kt
ÎļþÒÑɾ³ý
src/main/java/com/flightfeather/monitor/scheduledtasks/TaskController.kt
@@ -1,6 +1,8 @@
package com.flightfeather.monitor.scheduledtasks
import lombok.extern.slf4j.Slf4j
import com.flightfeather.monitor.scheduledtasks.dust.DustDailyAnalysisTask
import com.flightfeather.monitor.scheduledtasks.dust.DustExceptionAnalysisTask
import com.flightfeather.monitor.scheduledtasks.dust.DustMonthlyAnalysisTask
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
@@ -17,9 +19,8 @@
@Component
class TaskController(
    dustExceptionAnalysisTask: DustExceptionAnalysisTask,
    dustDailyStatisticAnalysisTask: DustDailyStatisticAnalysisTask,
    dustMonthlyStatisticAnalysisTask: DustMonthlyStatisticAnalysisTask,
    dustAnalysisTask: DustAnalysisTask,
    dustDailyAnalysisTask: DustDailyAnalysisTask,
    dustMonthlyAnalysisTask: DustMonthlyAnalysisTask,
) {
    companion object {
@@ -37,10 +38,9 @@
    init {
        log.info("添加定时任务")
        timeTask.clear()
//        timeTask.add(dustExceptionAnalysisTask)
//        timeTask.add(dustDailyStatisticAnalysisTask)
//        timeTask.add(dustMonthlyStatisticAnalysisTask)
        timeTask.add(dustAnalysisTask)
        timeTask.add(dustExceptionAnalysisTask)
        timeTask.add(dustDailyAnalysisTask)
        timeTask.add(dustMonthlyAnalysisTask)
        log.info("添加定时任务完成,任务总计${timeTask.size}个")
    }
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/BaseDustTimingTask.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,29 @@
package com.flightfeather.monitor.scheduledtasks.dust
import com.flightfeather.monitor.domain.ds1.repository.RequestTaskRep
import com.flightfeather.monitor.scheduledtasks.BaseTimingTask
import java.time.LocalDateTime
abstract class BaseDustTimingTask(private val requestTaskRep: RequestTaskRep) : BaseTimingTask() {
    // ä»»åŠ¡æ˜¯å¦å»¶è¿Ÿæ‰§è¡Œ
    protected var taskDelay = false
    // æœªä½¿ç”¨åˆ°
    override val period: Long = 15L
    override fun execute(localtime: LocalDateTime) {
        doTask(localtime)
    }
    /**
     * å½“任务开始执行时,判断任务状态,决定是否延迟执行
     */
    protected fun isTaskDelay(localtime: LocalDateTime): Boolean {
        val task = requestTaskRep.findLatestTask(localtime)
        // ä»»åŠ¡æ­£åœ¨æ‰§è¡Œï¼Œè·³è¿‡æ­¤æ¬¡åˆ†æžï¼Œåœ¨ä¸‹ä¸€å‘¨æœŸç»§ç»­åˆ¤æ–­ï¼Œç­‰å¾…ä»»åŠ¡å®ŒæˆåŽè¿›è¡Œåˆ†æž
        return if (task == null || task.runningStatus) {
            true
        } else !task.success
    }
}
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/DustDailyAnalysisTask.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,26 @@
package com.flightfeather.monitor.scheduledtasks.dust
import com.flightfeather.monitor.analysis.dust.StatisticAnalysisController
import com.flightfeather.monitor.domain.ds1.repository.RequestTaskRep
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
 * æ‰¬å°˜æ—¥ç»Ÿè®¡åˆ†æžä»»åŠ¡
 */
@Component
class DustDailyAnalysisTask(
    private val statisticAnalysisController: StatisticAnalysisController,
    requestTaskRep: RequestTaskRep,
) : BaseDustTimingTask(requestTaskRep) {
    override fun doTask(localtime: LocalDateTime) {
        if (taskDelay || (localtime.hour == 9 && localtime.minute == 0)) {
            taskDelay = isTaskDelay(localtime)
            if (!taskDelay) {
                log.info("日分析执行")
                statisticAnalysisController.autoRunDailyStatics()
            }
        }
    }
}
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/DustExceptionAnalysisTask.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,29 @@
package com.flightfeather.monitor.scheduledtasks.dust
import com.flightfeather.monitor.analysis.dust.ExceptionAnalysisController
import com.flightfeather.monitor.domain.ds1.repository.RequestTaskRep
import com.flightfeather.monitor.scheduledtasks.BaseTimingTask
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
 * æ‰¬å°˜æ•°æ®å¼‚常统计分析任务
 */
@Component
class DustExceptionAnalysisTask(
    private val exceptionAnalysisController: ExceptionAnalysisController,
    requestTaskRep: RequestTaskRep,
) : BaseDustTimingTask(requestTaskRep) {
    override fun doTask(localtime: LocalDateTime) {
        if (taskDelay || (localtime.hour == 8 && localtime.minute == 0)) {
            // åˆ¤æ–­ä»Šæ—¥çˆ¬å–任务是否完成
            taskDelay = isTaskDelay(localtime)
            if (!taskDelay) {
                log.info("异常分析执行")
                exceptionAnalysisController.init()
                exceptionAnalysisController.autoRun()
            }
        }
    }
}
src/main/java/com/flightfeather/monitor/scheduledtasks/dust/DustMonthlyAnalysisTask.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,27 @@
package com.flightfeather.monitor.scheduledtasks.dust
import com.flightfeather.monitor.analysis.dust.StatisticAnalysisController
import com.flightfeather.monitor.domain.ds1.repository.RequestTaskRep
import com.flightfeather.monitor.scheduledtasks.BaseTimingTask
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
 * æ‰¬å°˜æœˆç»Ÿè®¡åˆ†æžä»»åŠ¡
 */
@Component
class DustMonthlyAnalysisTask(
    private val statisticAnalysisController: StatisticAnalysisController,
    requestTaskRep: RequestTaskRep,
) : BaseDustTimingTask(requestTaskRep) {
    override fun doTask(localtime: LocalDateTime) {
        if (taskDelay || (localtime.dayOfMonth == 1 && localtime.hour == 9 && localtime.minute == 0)) {
            taskDelay = isTaskDelay(localtime)
            if (!taskDelay) {
                log.info("月分析执行")
                statisticAnalysisController.autoRunMonthlyStatics()
            }
        }
    }
}
src/test/java/com/flightfeather/monitor/scheduledtasks/DustAnalysisTaskTest.kt
ÎļþÒÑɾ³ý