[dev] use script's exitValue to deterime whether the task is success (issue#28)

This commit is contained in:
朱八 2020-07-23 20:09:10 +08:00
parent 557248ff89
commit 4c9a647132
2 changed files with 24 additions and 5 deletions

View File

@ -96,7 +96,9 @@ public abstract class ScriptProcessor implements BasicProcessor {
}
String result = String.format("[INPUT]: %s;[ERROR]: %s", inputSB.toString(), errorSB.toString());
return new ProcessResult(true, result);
// 0 代表正常退出
int exitValue = process.exitValue();
return new ProcessResult(exitValue == 0, result);
}catch (InterruptedException ie) {
omsLogger.info("SYSTEM===> ScriptProcessor has been interrupted");
return new ProcessResult(false, "Interrupted");

View File

@ -1,9 +1,14 @@
package com.github.kfcfans.powerjob;
import com.github.kfcfans.powerjob.worker.core.processor.TaskContext;
import com.github.kfcfans.powerjob.worker.core.processor.built.PythonProcessor;
import com.github.kfcfans.powerjob.worker.core.processor.built.ShellProcessor;
import com.github.kfcfans.powerjob.worker.log.impl.OmsServerLogger;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.concurrent.ThreadLocalRandom;
/**
* 测试脚本处理器
*
@ -14,25 +19,37 @@ public class ScriptProcessorTest {
private static final long timeout = 10000;
private static final TaskContext context = new TaskContext();
@BeforeAll
public static void initContext() {
context.setOmsLogger(new OmsServerLogger(1L));
}
@Test
public void testLocalShellProcessor() throws Exception {
ShellProcessor sp = new ShellProcessor(1L, "ls -a", timeout);
sp.process(null);
System.out.println(sp.process(context));
ShellProcessor sp2 = new ShellProcessor(2777L, "pwd", timeout);
sp2.process(null);
System.out.println(sp2.process(context));
}
@Test
public void testLocalPythonProcessor() throws Exception {
PythonProcessor pp = new PythonProcessor(2L, "print 'Hello World!'", timeout);
pp.process(null);
System.out.println(pp.process(context));
}
@Test
public void testNetShellProcessor() throws Exception {
ShellProcessor sp = new ShellProcessor(18L, "http://localhost:8080/test/test.sh", timeout);
sp.process(null);
System.out.println(sp.process(context));
}
@Test
public void testFailedScript() throws Exception {
ShellProcessor sp3 = new ShellProcessor(ThreadLocalRandom.current().nextLong(), "mvn tjq", timeout);
System.out.println(sp3.process(context));
}
}