Skip to content

Commit

Permalink
refactor: remove unuse code
Browse files Browse the repository at this point in the history
  • Loading branch information
霄鸿 committed Jan 25, 2024
1 parent f68b9b6 commit 7bc16f2
Showing 1 changed file with 34 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import io.holoinsight.server.common.AddressUtil;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.config.ProdLog;
import io.holoinsight.server.common.config.ScheduleLoadTask;
import io.holoinsight.server.home.biz.common.MetaDictUtil;
import io.holoinsight.server.home.biz.service.ClusterService;
import io.holoinsight.server.home.biz.service.ClusterTaskService;
import io.holoinsight.server.home.biz.service.impl.ClusterTaskServiceImpl;
import io.holoinsight.server.home.common.util.CLUSTER_ROLE_CONST;
import io.holoinsight.server.home.common.util.Debugger;
import io.holoinsight.server.common.config.ProdLog;
import io.holoinsight.server.common.config.ScheduleLoadTask;
import io.holoinsight.server.home.dal.model.ClusterTask;
import io.holoinsight.server.home.dal.model.dto.ClusterDTO;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
*
Expand All @@ -31,7 +30,6 @@
*/
@Service
public class MonitorTaskManager extends ScheduleLoadTask {
private static AtomicBoolean STARTED = new AtomicBoolean(false);

@Autowired
private ClusterTaskService clusterTaskService;
Expand All @@ -40,7 +38,7 @@ public class MonitorTaskManager extends ScheduleLoadTask {
private ClusterService clusterService;

@Override
public void load() throws Exception {
public void load() {
try {
// 这里任务周期
long current = System.currentTimeMillis();
Expand Down Expand Up @@ -110,7 +108,7 @@ private void schedule(List<ClusterDTO> metaClusters, long period) {
ct.setGmtCreate(new Date());
ct.setGmtModified(new Date());
cts.add(ct);
ProdLog.info("task detail:" + ct.toString());
ProdLog.info("task detail:" + ct);
}

if (!CollectionUtils.isEmpty(cts)) {
Expand Down Expand Up @@ -164,19 +162,16 @@ private void slaveWork(long period) {
continue;
}

task.getCorePool().submit(new Runnable() {
@Override
public void run() {
try {
task.CORE_JOBS.incrementAndGet();
taskJobBuild(task, period, ct);
clusterTaskService.doneTask(ct, true, null);
} catch (Throwable e) {
ProdLog.error(task.getTaskId() + "-" + period + ", build jobs error", e);
clusterTaskService.doneTask(ct, false, e.getMessage());
} finally {
task.CORE_JOBS.decrementAndGet();
}
task.getCorePool().submit(() -> {
try {
task.CORE_JOBS.incrementAndGet();
taskJobBuild(task, period, ct);
clusterTaskService.doneTask(ct, true, null);
} catch (Throwable e) {
ProdLog.error(task.getTaskId() + "-" + period + ", build jobs error", e);
clusterTaskService.doneTask(ct, false, e.getMessage());
} finally {
task.CORE_JOBS.decrementAndGet();
}
});
}
Expand All @@ -198,30 +193,26 @@ public void taskJobBuild(AbstractMonitorTask task, long period, ClusterTask ct)
}
for (MonitorTaskJob job : jobs) {
try {
task.getPool().submit(new Runnable() {
@Override
public void run() {
task.RUNNING_JOBS.incrementAndGet(); // 增加一个Job
long s = System.currentTimeMillis();
long end;
try {
job.run();
end = System.currentTimeMillis();
ProdLog.monitor("TASK_MANAGER", task.getTaskId(), job.id(), "Y", "", true, end - s,
1);
ProdLog.info(task.getTaskId() + "-" + period + "-" + job.id()
+ ", work success, cost:" + (end - s));
} catch (Throwable e) {
end = System.currentTimeMillis();
ProdLog.monitor("TASK_MANAGER", task.getTaskId(), job.id(), "N", "", false, end - s,
1);
ProdLog.error(task.getTaskId() + "-" + period + "-" + job.id()
+ ", work failed, cost:" + (end - s), e);
} finally {
// 计数减1,Job
task.RUNNING_JOBS.decrementAndGet();
ProdLog.info(task.getTaskId() + "-" + period + ", close job:" + job.id());
}
task.getPool().submit(() -> {
task.RUNNING_JOBS.incrementAndGet(); // 增加一个Job
long s1 = System.currentTimeMillis();
long end;
try {
job.run();
end = System.currentTimeMillis();
ProdLog.monitor("TASK_MANAGER", task.getTaskId(), job.id(), "Y", "", true, end - s1, 1);
ProdLog.info(task.getTaskId() + "-" + period + "-" + job.id() + ", work success, cost:"
+ (end - s1));
} catch (Throwable e) {
end = System.currentTimeMillis();
ProdLog.monitor("TASK_MANAGER", task.getTaskId(), job.id(), "N", "", false, end - s1,
1);
ProdLog.error(task.getTaskId() + "-" + period + "-" + job.id() + ", work failed, cost:"
+ (end - s1), e);
} finally {
// 计数减1,Job
task.RUNNING_JOBS.decrementAndGet();
ProdLog.info(task.getTaskId() + "-" + period + ", close job:" + job.id());
}
});
} catch (Exception e) {
Expand Down

0 comments on commit 7bc16f2

Please sign in to comment.