[ server ] [ scheduler ]- script scheduler - 4
This commit is contained in:
@@ -51,13 +51,14 @@ public class OMHandlerExecutor extends AbstractOctopusMessageHandler {
|
||||
// add in 2023-1-17
|
||||
if (CollectionUtils.isNotEmpty(executionMessage.getScriptCommandList())) {
|
||||
// 传递的是 页面定时任务脚本
|
||||
isScheduledScript = true;
|
||||
functionExecutor.execute(executionMessage, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
String executionType = executionMessage.getType();
|
||||
if (ALL_FUNCTION_MAP.containsKey(executionType)) {
|
||||
// execute the exist function
|
||||
functionExecutor.execute(executionMessage, isScheduledScript);
|
||||
functionExecutor.execute(executionMessage, false);
|
||||
} else {
|
||||
// handle command
|
||||
commandExecutor.execute(executionMessage);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -28,11 +28,6 @@ public class FunctionExecutor {
|
||||
NacosConfigurationCollector nacosConfigurationCollector;
|
||||
|
||||
|
||||
public void executeScriptScheduler(ExecutionMessage executionMessage) {
|
||||
|
||||
executionMessage.getScriptCommandList();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void execute(ExecutionMessage executionMessage, boolean isScheduledScript) {
|
||||
|
||||
@@ -30,8 +30,8 @@ public class BuildStatusScheduleTask {
|
||||
@Value(value = "${octopus.status.healthy.start-delay}")
|
||||
int healthyCheckStartDelaySeconds;
|
||||
|
||||
@Value(value = "${octopus.status.metric.cron}")
|
||||
int metricReportCronExpress;
|
||||
// @Value(value = "${octopus.status.metric.cron}")
|
||||
// int metricReportCronExpress;
|
||||
|
||||
@Value(value = "${octopus.status.metric.pinch}")
|
||||
int metricReportTimePinch;
|
||||
|
||||
@@ -4,6 +4,7 @@ package io.wdd.rpc.scheduler.service.script;
|
||||
import io.wdd.rpc.execute.service.CoreExecutionService;
|
||||
import io.wdd.rpc.scheduler.beans.ScriptSchedulerDTO;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -13,7 +14,7 @@ import java.util.List;
|
||||
* 1.
|
||||
*/
|
||||
@Service
|
||||
@Log4j
|
||||
@Slf4j
|
||||
public class AgentApplyScheduledScript {
|
||||
|
||||
@Resource
|
||||
|
||||
@@ -8,6 +8,8 @@ import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.wdd.rpc.scheduler.service.status.MonitorAllAgentStatus.ALL_AGENT_TOPIC_NAME_SET;
|
||||
|
||||
@SpringBootTest
|
||||
class ServerApplicationTests {
|
||||
|
||||
@@ -35,7 +37,7 @@ class ServerApplicationTests {
|
||||
ArrayList<String> command3 = new ArrayList<>(
|
||||
List.of(
|
||||
"echo",
|
||||
"no"
|
||||
"\"no\""
|
||||
)
|
||||
);
|
||||
|
||||
@@ -55,6 +57,8 @@ class ServerApplicationTests {
|
||||
completeScript.add(command4);
|
||||
|
||||
|
||||
ALL_AGENT_TOPIC_NAME_SET.add("Chengdu-amd64-98-98066f");
|
||||
|
||||
ArrayList<String> targetMachineList = new ArrayList<>(
|
||||
List.of(
|
||||
"Chengdu-amd64-98-98066f"
|
||||
|
||||
Reference in New Issue
Block a user