Browse Source

[Feature] python task logs print delayed (#1844)

* [Feature] python task logs print delayed
#1843
pull/2/head
gabry.wu 5 years ago committed by Tboy
parent
commit
abe80fc538
  1. 18
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractCommandExecutor.java
  2. 11
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/PythonCommandExecutor.java

18
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractCommandExecutor.java

@ -30,10 +30,7 @@ import org.slf4j.Logger;
import java.io.*; import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -207,7 +204,14 @@ public abstract class AbstractCommandExecutor {
// merge error information to standard output stream // merge error information to standard output stream
processBuilder.redirectErrorStream(true); processBuilder.redirectErrorStream(true);
// setting up user to run commands // setting up user to run commands
processBuilder.command("sudo", "-u", tenantCode, commandInterpreter(), commandFile); List<String> command = new LinkedList<>();
command.add("sudo");
command.add("-u");
command.add(tenantCode);
command.add(commandInterpreter());
command.addAll(commandOptions());
command.add(commandFile);
processBuilder.command(command);
process = processBuilder.start(); process = processBuilder.start();
@ -559,7 +563,9 @@ public abstract class AbstractCommandExecutor {
} }
} }
protected List<String> commandOptions() {
return Collections.emptyList();
}
protected abstract String buildCommandFilePath(); protected abstract String buildCommandFilePath();
protected abstract String commandInterpreter(); protected abstract String commandInterpreter();
protected abstract boolean checkFindApp(String line); protected abstract boolean checkFindApp(String line);

11
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/PythonCommandExecutor.java

@ -26,6 +26,7 @@ import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -108,6 +109,16 @@ public class PythonCommandExecutor extends AbstractCommandExecutor {
} }
} }
/**
* get command options
* @return command options list
*/
@Override
protected List<String> commandOptions() {
// unbuffered binary stdout and stderr
return Collections.singletonList("-u");
}
/** /**
* get python home * get python home
* @return python home * @return python home

Loading…
Cancel
Save