package cn.flightfeather.supervision.lightshare.service.impl
|
|
import cn.flightfeather.supervision.common.exception.ResponseErrorException
|
import cn.flightfeather.supervision.common.executor.BackgroundTaskCtrl
|
import cn.flightfeather.supervision.common.executor.BgTaskConditionVo
|
import cn.flightfeather.supervision.common.executor.BgTaskStatus
|
import cn.flightfeather.supervision.common.executor.BgTaskType
|
import cn.flightfeather.supervision.lightshare.service.BgTaskService
|
import org.springframework.stereotype.Service
|
|
@Service
|
class BgTaskServiceImpl(private val backgroundTaskCtrl: BackgroundTaskCtrl) : BgTaskService {
|
|
override fun getTaskStatus(condition: BgTaskConditionVo): List<BgTaskStatus?> {
|
return backgroundTaskCtrl.getTaskStatus(condition.type, condition.id)
|
}
|
|
override fun startTask(condition: BgTaskConditionVo): BgTaskStatus? {
|
condition.type ?: throw ResponseErrorException("任务类型不能为空")
|
condition.id ?: throw ResponseErrorException("任务id不能为空")
|
|
val task = backgroundTaskCtrl.startTask(condition.type!!, condition.id!!)
|
return task.taskStatus
|
}
|
|
override fun shutDownTask(condition: BgTaskConditionVo): List<BgTaskStatus?> {
|
condition.type ?: throw ResponseErrorException("任务类型不能为空")
|
return backgroundTaskCtrl.shutDownTask(condition.type!!, condition.id)
|
}
|
|
override fun removeTask(condition: BgTaskConditionVo): Boolean {
|
condition.type ?: throw ResponseErrorException("任务类型不能为空")
|
condition.id ?: throw ResponseErrorException("任务id不能为空")
|
return backgroundTaskCtrl.removeTask(condition.type!!, condition.id!!)
|
}
|
|
override fun startNewTestTask(taskId: String): BgTaskStatus? {
|
val task = backgroundTaskCtrl.startNewTask(BgTaskType.TEST, taskId, "测试任务-${taskId}") { testTask() }
|
return task.taskStatus
|
}
|
|
override fun newTestTask(taskId: String): BgTaskStatus? {
|
val task = backgroundTaskCtrl.newTask(BgTaskType.TEST, taskId, "测试任务-${taskId}") { testTask() }
|
return task.taskStatus
|
}
|
|
private fun testTask(): Boolean {
|
var times = 10
|
while (times > 0) {
|
Thread.sleep(2000)
|
times--
|
}
|
return true
|
}
|
}
|