|
|
@@ -5,6 +5,8 @@ import cn.seecoder.web.dao.pipeline.DeploymentMapper;
|
|
|
import cn.seecoder.web.dao.pipeline.PipelineMapper;
|
|
|
import cn.seecoder.web.model.po.pipeline.DeploymentPO;
|
|
|
import cn.seecoder.web.model.po.pipeline.PipelinePO;
|
|
|
+import cn.seecoder.web.model.vo.user.UserVO;
|
|
|
+import cn.seecoder.web.service.devmanage.DevmanageService;
|
|
|
import cn.seecoder.web.service.pipeline.DeploymentService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -13,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -23,26 +26,34 @@ public class ScheduledTasks {
|
|
|
private final DeploymentService deploymentService;
|
|
|
private final DeploymentMapper deploymentMapper;
|
|
|
private final PipelineMapper pipelineMapper;
|
|
|
+ private final DevmanageService devmanageService;
|
|
|
+ private final String[] PHONES_TO_SKIP = new String[] {"18001585267"};
|
|
|
+ private final SchedulerHelper schedulerHelper;
|
|
|
|
|
|
-// @Scheduled(cron = "0 0 1 * * ?")
|
|
|
-// public void purgeZombieDeployments() {
|
|
|
-// final long ONE_DAY_MILLIS = 86400000L;
|
|
|
-// final long HALF_DAY_MILLIS = 43200000L;
|
|
|
-// Timestamp expireLimit = new Timestamp(System.currentTimeMillis() - HALF_DAY_MILLIS);
|
|
|
-// List<DeploymentPO> deploymentPOList = deploymentMapper.selectAllDeployments();
|
|
|
-// for (DeploymentPO deploymentPO: deploymentPOList) {
|
|
|
-// Timestamp deployedTime = deploymentPO.getDeployedTime();
|
|
|
-// if (deployedTime.before(expireLimit)) {
|
|
|
-// PipelinePO pipelinePO = pipelineMapper.selectById(deploymentPO.getPipelineId());
|
|
|
-// try {
|
|
|
-// deploymentService.delete(pipelinePO.getProjectId(), deploymentPO.getPipelineId());
|
|
|
-// } catch (AccessDeniedException e) {
|
|
|
-// log.error(String.format("Scheduled Deployments Purge Failed for projectId: %s, pipelineId: %s, for %s",
|
|
|
-// pipelinePO.getProjectId(),
|
|
|
-// deploymentPO.getPipelineId(),
|
|
|
-// e.getMessage()));
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ @Scheduled(cron = "0 0 1 * * ?")
|
|
|
+ public void purgeZombieDeployments() {
|
|
|
+ if (schedulerHelper.getEnableTasks()) {
|
|
|
+ final long ONE_DAY_MILLIS = 86400000L;
|
|
|
+ final long HALF_DAY_MILLIS = 43200000L;
|
|
|
+ Timestamp expireLimit = new Timestamp(System.currentTimeMillis() - HALF_DAY_MILLIS);
|
|
|
+ List<DeploymentPO> deploymentPOList = deploymentMapper.selectAllDeployments();
|
|
|
+ for (DeploymentPO deploymentPO : deploymentPOList) {
|
|
|
+ Timestamp deployedTime = deploymentPO.getDeployedTime();
|
|
|
+ String namespace = deploymentPO.getNamespace();
|
|
|
+ UserVO ownerOfNamespace = devmanageService.getOwnerOfNamespace(namespace);
|
|
|
+ String phone = ownerOfNamespace.getPhone();
|
|
|
+ if (deployedTime.before(expireLimit) && !Arrays.asList(PHONES_TO_SKIP).contains(phone)) {
|
|
|
+ PipelinePO pipelinePO = pipelineMapper.selectById(deploymentPO.getPipelineId());
|
|
|
+ try {
|
|
|
+ deploymentService.delete(pipelinePO.getProjectId(), deploymentPO.getPipelineId());
|
|
|
+ } catch (AccessDeniedException e) {
|
|
|
+ log.error(String.format("Scheduled Deployments Purge Failed for projectId: %s, pipelineId: %s, for %s",
|
|
|
+ pipelinePO.getProjectId(),
|
|
|
+ deploymentPO.getPipelineId(),
|
|
|
+ e.getMessage()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|