New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JBPM-9334] Process execution stuck at ExecWorkItemHandler node if co… #147
Conversation
…mmand is long running.
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
9 similar comments
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
Can one of the admins verify this PR? Comment with 'ok to test' to start the build. |
ok to test |
@@ -43,7 +47,8 @@ | |||
icon = "Exec.png", | |||
parameters = { | |||
@WidParameter(name = "Command", required = true), | |||
@WidParameter(name = "Arguments", runtimeType = "java.util.List") | |||
@WidParameter(name = "Arguments", runtimeType = "java.util.List"), | |||
@WidParameter(name = "CommandExecutionTimeout", runtimeType = "java.lang.String") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just "Timeout" would be simpler here, but not a big deal at all.
Also specifying the expected time value (seconds, minutes, hours) would be nice.
So if you expect seconds you could call it "TimeoutInSeconds" for example.
@@ -104,6 +131,10 @@ public void abortWorkItem(WorkItem workItem, | |||
WorkItemManager manager) { | |||
// Do nothing, this work item cannot be aborted | |||
} | |||
|
|||
public void SetDefaultTimeoutInSeconds(long defaultTimeoutInSeconds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method name should start with lower case letter.
String commandExecutionTimeout = (String) workItem.getParameter("CommandExecutionTimeout"); | ||
|
||
if (commandExecutionTimeout ==null) { | ||
this.SetDefaultTimeoutInSeconds(4L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just initialize defaultTimeoutInSeconds up front with this value then you dont need to do it here.
@@ -71,6 +78,13 @@ public void executeWorkItem(WorkItem workItem, | |||
|
|||
String command = (String) workItem.getParameter("Command"); | |||
List<String> arguments = (List<String>) workItem.getParameter("Arguments"); | |||
String commandExecutionTimeout = (String) workItem.getParameter("CommandExecutionTimeout"); | |||
|
|||
if (commandExecutionTimeout ==null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commandExecutionTimeout is a string, so you should also check if its empty, and if it actually is a time.
Also if you are expecting the timeout to be in seconds, then the parameter should prob change to make sure thats clear, for example "TimeoutInSeconds" or something that is clear to readers what is expected.
You can also look into using ISO 8601 if possible to describe the time, for example "PT2M" for "2 minutes" etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -82,11 +96,24 @@ public void executeWorkItem(WorkItem workItem, | |||
|
|||
parsedCommandStr = commandLine.toString(); | |||
|
|||
ExecuteWatchdog watchdog = new ExecuteWatchdog(java.time.Duration.ofSeconds(defaultTimeoutInSeconds).toMillis()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use import rather than full path (java.time.Duration)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} catch (IOException e) { | ||
if (watchdog.killedProcess()) { | ||
logger.debug("A timeout occured after "+java.time.Duration.ofSeconds(defaultTimeoutInSeconds).toMillis()+"ms while executing a command "+parsedCommandStr.replace(",", "")); | ||
results.put(RESULT, outputStream.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there was a timeout error / exception then I assume outputstream is empty ? wonder if you should return a default value or none at all here. Consider also how will the process know that there the execution of this command failed? Maybe a specific return value can be used that lets the rest of the process be able to reason over a possible failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outputstream do have a partial response for ping command. But sending partial response is not good idea. I have added failure message in result object in case of timeout and also added logger to log error.
@@ -85,6 +85,35 @@ public void testExecCommandWithArguments() throws Exception { | |||
assertNotNull(result); | |||
assertTrue(result.contains("java version") || result.contains("jdk version")); | |||
} | |||
|
|||
@Test(timeout=6000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont understand how this test method actually tests the code that you have added in the handler :) please explain. Need a test that actually times out to test that the timeout is actually handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this test I am executing ping command, when we execute ping command from the terminal we have to manually terminate the command. Here junit test will wait for 5 seconds to complete its executiom. If command execution didnt terminated/completed within 5 secs, test will keep running for its completion. So to terminate junit test added 6 seconds timeout for test.
Thanks for the PR! Left some comments. Also for this PR and last one you did I wonder if the code could be formatted in your editor? |
…mmand is long running
Seems issue with IDE code format. Do we have any same code to includude in IDE formattter/code style ? |
@abhijithumbe One small thing I noticed is that in #145 it also has a timeout parameter that expects milliseconds and called "TimeoutInMillis" - do you think we could align the two so they are the same? Probably little confusing that one workitem expects milliseconds and the other seconds. WDYT? |
Thanks for the contribution and doing all the updates! |
Jenkins retest this |
…mmand is long running
updated WIH to accept timeout in milliseconds. |
Thank you for all your help :) Now code should be in the required format. Kindly review latest commit |
@abhijithumbe LGTM @MarianMacik same here- do we need a QE review or can merge ? |
Jenkins retest please |
@MarianMacik can you please share thoughts on this ? |
…mmand is long running
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just formatting. Otherwise looks good. Thanks a lot for the improvement!
exec-workitem/src/main/java/org/jbpm/process/workitem/exec/ExecWorkItemHandler.java
Outdated
Show resolved
Hide resolved
exec-workitem/src/test/java/org/jbpm/process/workitem/exec/ExecWorkItemHandlerTest.java
Outdated
Show resolved
Hide resolved
…mmand is long running
@MarianMacik Could you please review? |
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
…mmand is long running
kiegroup#147) * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running. * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running * [JBPM-9334] Process execution stuck at ExecWorkItemHandler node if command is long running
…mmand is long running.
Thank you for submitting this pull request
JIRA: (please edit the JIRA link if it exists)
link
referenced Pull Requests: (please edit the URLs of referenced pullrequests if they exist)