mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[dev] use script's exitValue to deterime whether the task is success (issue#28)
This commit is contained in:
parent
557248ff89
commit
4c9a647132
@ -96,7 +96,9 @@ public abstract class ScriptProcessor implements BasicProcessor {
|
|||||||
}
|
}
|
||||||
String result = String.format("[INPUT]: %s;[ERROR]: %s", inputSB.toString(), errorSB.toString());
|
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) {
|
}catch (InterruptedException ie) {
|
||||||
omsLogger.info("SYSTEM===> ScriptProcessor has been interrupted");
|
omsLogger.info("SYSTEM===> ScriptProcessor has been interrupted");
|
||||||
return new ProcessResult(false, "Interrupted");
|
return new ProcessResult(false, "Interrupted");
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package com.github.kfcfans.powerjob;
|
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.PythonProcessor;
|
||||||
import com.github.kfcfans.powerjob.worker.core.processor.built.ShellProcessor;
|
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 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 long timeout = 10000;
|
||||||
|
|
||||||
|
private static final TaskContext context = new TaskContext();
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void initContext() {
|
||||||
|
context.setOmsLogger(new OmsServerLogger(1L));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalShellProcessor() throws Exception {
|
public void testLocalShellProcessor() throws Exception {
|
||||||
ShellProcessor sp = new ShellProcessor(1L, "ls -a", timeout);
|
ShellProcessor sp = new ShellProcessor(1L, "ls -a", timeout);
|
||||||
sp.process(null);
|
System.out.println(sp.process(context));
|
||||||
|
|
||||||
ShellProcessor sp2 = new ShellProcessor(2777L, "pwd", timeout);
|
ShellProcessor sp2 = new ShellProcessor(2777L, "pwd", timeout);
|
||||||
sp2.process(null);
|
System.out.println(sp2.process(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalPythonProcessor() throws Exception {
|
public void testLocalPythonProcessor() throws Exception {
|
||||||
PythonProcessor pp = new PythonProcessor(2L, "print 'Hello World!'", timeout);
|
PythonProcessor pp = new PythonProcessor(2L, "print 'Hello World!'", timeout);
|
||||||
pp.process(null);
|
System.out.println(pp.process(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetShellProcessor() throws Exception {
|
public void testNetShellProcessor() throws Exception {
|
||||||
ShellProcessor sp = new ShellProcessor(18L, "http://localhost:8080/test/test.sh", timeout);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user