[ server ] [ scheduler ]- script scheduler - 4

This commit is contained in:
zeaslity
2023-01-17 17:34:51 +08:00
parent e080d3f858
commit 4acba4ce8e
6 changed files with 65 additions and 13 deletions

View File

@@ -51,13 +51,14 @@ public class OMHandlerExecutor extends AbstractOctopusMessageHandler {
// add in 2023-1-17 // add in 2023-1-17
if (CollectionUtils.isNotEmpty(executionMessage.getScriptCommandList())) { if (CollectionUtils.isNotEmpty(executionMessage.getScriptCommandList())) {
// 传递的是 页面定时任务脚本 // 传递的是 页面定时任务脚本
isScheduledScript = true; functionExecutor.execute(executionMessage, true);
return true;
} }
String executionType = executionMessage.getType(); String executionType = executionMessage.getType();
if (ALL_FUNCTION_MAP.containsKey(executionType)) { if (ALL_FUNCTION_MAP.containsKey(executionType)) {
// execute the exist function // execute the exist function
functionExecutor.execute(executionMessage, isScheduledScript); functionExecutor.execute(executionMessage, false);
} else { } else {
// handle command // handle command
commandExecutor.execute(executionMessage); commandExecutor.execute(executionMessage);

View File

@@ -47,6 +47,57 @@ public class CommandExecutor {
} }
/*public int executeScript(String streamKey, List<String> commandList) {
ProcessBuilder processBuilder = new ProcessBuilder(commandList);
processBuilder.redirectErrorStream(true);
// processBuilder.inheritIO();
processBuilder.directory(new File(System.getProperty("user.home")));
int processResult = 233;
try {
Process process = processBuilder.start();
// start a backend thread to daemon the process
// wait for processMaxWaitSeconds and kill the process if it's still alived
DaemonCommandProcess.submit(
StopStuckCommandProcess(
process,
processMaxWaitSeconds
));
// todo this will stuck the process and rabbitmq message will reentry the queue
// get the command result must also be a timeout smaller than the process
boolean waitFor = process.waitFor(
50,
TimeUnit.SECONDS
);
// get the process result
if (ObjectUtils.isNotEmpty(waitFor) && ObjectUtils.isNotEmpty(process)) {
processResult = process.exitValue();
}
log.debug(
"current shell command {} result is {}",
processBuilder.command(),
processResult
);
} catch (IOException | InterruptedException e) {
log.error(
"Shell command error ! {} + {}",
e.getCause(),
e.getMessage()
);
}
return processResult;
}*/
public int execute(String streamKey, List<String> command) { public int execute(String streamKey, List<String> command) {

View File

@@ -28,11 +28,6 @@ public class FunctionExecutor {
NacosConfigurationCollector nacosConfigurationCollector; NacosConfigurationCollector nacosConfigurationCollector;
public void executeScriptScheduler(ExecutionMessage executionMessage) {
executionMessage.getScriptCommandList();
}
public void execute(ExecutionMessage executionMessage, boolean isScheduledScript) { public void execute(ExecutionMessage executionMessage, boolean isScheduledScript) {

View File

@@ -30,8 +30,8 @@ public class BuildStatusScheduleTask {
@Value(value = "${octopus.status.healthy.start-delay}") @Value(value = "${octopus.status.healthy.start-delay}")
int healthyCheckStartDelaySeconds; int healthyCheckStartDelaySeconds;
@Value(value = "${octopus.status.metric.cron}") // @Value(value = "${octopus.status.metric.cron}")
int metricReportCronExpress; // int metricReportCronExpress;
@Value(value = "${octopus.status.metric.pinch}") @Value(value = "${octopus.status.metric.pinch}")
int metricReportTimePinch; int metricReportTimePinch;

View File

@@ -4,6 +4,7 @@ package io.wdd.rpc.scheduler.service.script;
import io.wdd.rpc.execute.service.CoreExecutionService; import io.wdd.rpc.execute.service.CoreExecutionService;
import io.wdd.rpc.scheduler.beans.ScriptSchedulerDTO; import io.wdd.rpc.scheduler.beans.ScriptSchedulerDTO;
import lombok.extern.log4j.Log4j; import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -13,7 +14,7 @@ import java.util.List;
* 1. * 1.
*/ */
@Service @Service
@Log4j @Slf4j
public class AgentApplyScheduledScript { public class AgentApplyScheduledScript {
@Resource @Resource

View File

@@ -8,6 +8,8 @@ import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static io.wdd.rpc.scheduler.service.status.MonitorAllAgentStatus.ALL_AGENT_TOPIC_NAME_SET;
@SpringBootTest @SpringBootTest
class ServerApplicationTests { class ServerApplicationTests {
@@ -20,8 +22,8 @@ class ServerApplicationTests {
ArrayList<String> command1 = new ArrayList<>( ArrayList<String> command1 = new ArrayList<>(
List.of( List.of(
"echo", "echo",
"yes" "yes"
) )
); );
@@ -35,7 +37,7 @@ class ServerApplicationTests {
ArrayList<String> command3 = new ArrayList<>( ArrayList<String> command3 = new ArrayList<>(
List.of( List.of(
"echo", "echo",
"no" "\"no\""
) )
); );
@@ -55,6 +57,8 @@ class ServerApplicationTests {
completeScript.add(command4); completeScript.add(command4);
ALL_AGENT_TOPIC_NAME_SET.add("Chengdu-amd64-98-98066f");
ArrayList<String> targetMachineList = new ArrayList<>( ArrayList<String> targetMachineList = new ArrayList<>(
List.of( List.of(
"Chengdu-amd64-98-98066f" "Chengdu-amd64-98-98066f"