Skip to content

Commit

Permalink
fix: Set the current parent pid in the Run Camel action
Browse files Browse the repository at this point in the history
  • Loading branch information
gansheer authored and christophd committed Dec 20, 2024
1 parent f643296 commit 01c4d8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
*/
public class ProcessAndOutput {

/** Logger */
/**
* Logger
*/
private static final Logger LOG = LoggerFactory.getLogger(ProcessAndOutput.class);

private final Process process;
Expand Down Expand Up @@ -140,6 +142,7 @@ private void readChunk() {
* Get the process id of first descendant or the parent process itself in case there is no descendant process.
* On Linux the shell command represents the parent process and the JBang command as descendant process.
* Typically, we need the JBang command process id.
*
* @return
*/
public Long getProcessId() {
Expand All @@ -150,9 +153,11 @@ public Long getProcessId() {
* Get the process id of first descendant or the parent process itself in case there is no descendant process.
* On Linux the shell command represents the parent process and the JBang command as descendant process.
* Typically, we need the JBang command process id.
*
* @return
*/
public Long getProcessId(String app) {

try {
if (app != null && isUnix()) {
// wait for descendant process to be available
Expand All @@ -173,13 +178,25 @@ public Long getProcessId(String app) {
}
}

/**
* Get the process id of the parent process.
* Typically, we need the JBang command process id.
*
* @return
*/
public Long getParentProcessId() {
return process.pid();
}


private static boolean isUnix() {
String os = System.getProperty("os.name").toLowerCase();
return os.contains("nix") || os.contains("nux") || os.contains("aix");
}

/**
* Sets the application name that identifies this process.
*
* @param app
*/
public void setApp(String app) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void doExecute(TestContext context) {
verifyProcessIsAlive(pao, name);

pao.setApp(integrationToRun.getFileName().toString());
Long pid = pao.getProcessId();
Long pid = pao.getParentProcessId();

context.setVariable(name + ":pid", pid);
context.setVariable(name + ":process:" + pid, pao);
Expand Down

0 comments on commit 01c4d8a

Please sign in to comment.