Below code is to trigger a sequential task. It was working perfectly fine. But recently we have upgraded to 8.3p3 and suddenly its started throwing NPE.
After debugging I got to know that tr.CompletionStatus value is Null. It makes sense that why it is throwing NPE.
TaskManager tm = new TaskManager(context);
TaskResult tr=tm.runWithResult(task,null);
if(tr.CompletionStatus.toString().equalsIgnoreCase("Error"))
{
throw new Exception("Task Failed");
}
I can write a logic to handle NPE. But my question is why it is working in 8.3p1 and it is not working in 8.3p3? Anyone face this issue?
Is there anyway to check task result status is completed or pending?
I have tried another way that you have suggested but still it is throwing error.
one thing I observe that I couldn’t see the completion status value on the debug page when I triggered the task. Completion status is getting updated only after task is completed. I think I need to write a logic to see if status is null or not.
"Error".equalsIgnoreCase(tr.getCompletionStatus())
Or Better Use StringUtils API method
https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringUtils.html#equalsIgnoreCase(java.lang.String,%20java.lang.String)
Your code should be like
import org.apache.commons.lang3.StringUtils;
TaskManager tm = new TaskManager(context);
TaskResult tr=tm.runWithResult(task,null);
if(StringUtils.equalsIgnoreCase(tr.CompletionStatus(), "Error"))
{
throw new Exception("Task Failed");
}
@pravin_ranjan It is working fine. I think the code that you have suggested, if completionStatus() value is “Error” then only it will enter into the block.
But I wanted to check the task result status after the completion. In my case, task is still running and its immediately returning the task result completion status in the rule as a value of Null.
I have tried with other option which is runSync().
runSync(): Run a task synchronously, bypassing the Quartz scheduler and returning the result to the same thread.
I thought this will helps me to get the task completion status. But it sill didn’t work.
Do you have any other thoughts to get the task result completion status after task is successfully completed?