use of org.jbpm.executor.AsyncJobException in project jbpm by kiegroup.
the class AsyncWorkItemHandlerCmdCallback method onCommandError.
@Override
public void onCommandError(CommandContext ctx, final Throwable exception) {
final Long processInstanceId = (Long) ctx.getData("processInstanceId");
final WorkItem workItem = (WorkItem) ctx.getData("workItem");
// find the right runtime to do the complete
RuntimeManager manager = getRuntimeManager(ctx);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
final ExecutionErrorHandler errorHandler = getExecutionErrorHandler(manager);
try {
boolean isErrorHandled = engine.getKieSession().execute(new ExecutableCommand<Boolean>() {
private static final long serialVersionUID = 1L;
@Override
public Boolean execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(processInstanceId);
NodeInstance nodeInstance = getNodeInstance(workItem, processInstance);
Throwable actualException = exception;
if (actualException instanceof AsyncJobException) {
actualException = exception.getCause();
}
String exceptionName = actualException.getClass().getName();
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
if (exceptionScopeInstance != null) {
logger.debug("Handling job error '{}' via process error handling", actualException.getMessage());
exceptionScopeInstance.handleException(exceptionName, actualException);
return true;
} else {
logger.debug("No process level error handling for '{}' letting it to be handled by execution errors", exception.getMessage());
errorHandler.processing(nodeInstance);
return false;
}
}
});
if (!isErrorHandled) {
logger.debug("Error '{}' was not handled on process level, handling it via execution errors mechanism", exception.getMessage());
errorHandler.handle(exception);
}
} catch (Exception e) {
logger.error("Error when handling callback from executor", e);
} finally {
manager.disposeRuntimeEngine(engine);
closeErrorHandler(manager);
}
}
use of org.jbpm.executor.AsyncJobException in project jbpm by kiegroup.
the class AbstractAvailableJobsExecutor method handleException.
@SuppressWarnings("unchecked")
protected boolean handleException(RequestInfo request, Throwable e, CommandContext ctx, List<CommandCallback> callbacks) {
logger.warn("Error during command {} error message {}", request.getCommandName(), e.getMessage(), e);
ErrorInfo errorInfo = new ErrorInfo(e.getMessage(), ExceptionUtils.getStackTrace(e.fillInStackTrace()));
errorInfo.setRequestInfo(request);
((List<ErrorInfo>) request.getErrorInfo()).add(errorInfo);
logger.debug("Error Number: {}", request.getErrorInfo().size());
if (request.getRetries() > 0) {
request.setStatus(STATUS.RETRYING);
request.setRetries(request.getRetries() - 1);
// calculate next retry time
List<Long> retryDelay = (List<Long>) ctx.getData("retryDelay");
if (retryDelay != null) {
long retryAdd = 0l;
try {
// need to decrement it as executions are directly incremented upon execution
retryAdd = retryDelay.get(request.getExecutions() - 1);
} catch (IndexOutOfBoundsException ex) {
// in case there is no element matching given execution, use last one
retryAdd = retryDelay.get(retryDelay.size() - 1);
}
request.setTime(new Date(System.currentTimeMillis() + retryAdd));
logger.info("Retrying request ( with id {}) - delay configured, next retry at {}", request.getId(), request.getTime());
}
logger.debug("Retrying ({}) still available!", request.getRetries());
executorStoreService.updateRequest(request, ((ExecutorImpl) executor).scheduleExecution(request, request.getTime()));
return false;
} else {
logger.debug("Error no retries left!");
request.setStatus(STATUS.ERROR);
executorStoreService.updateRequest(request, null);
AsyncJobException wrappedException = new AsyncJobException(request.getId(), request.getCommandName(), e);
if (callbacks != null) {
for (CommandCallback handler : callbacks) {
handler.onCommandError(ctx, wrappedException);
}
}
return true;
}
}
use of org.jbpm.executor.AsyncJobException in project jbpm by kiegroup.
the class JobExecutionErrorFilter method filter.
@Override
public ExecutionError filter(ExecutionErrorContext errorContext) {
AsyncJobException exception = extract(errorContext.getCause(), AsyncJobException.class);
String stacktrace = getStackTrace(exception);
NodeInstance nodeInstance = errorContext.getLastExecutedNode();
return ExecutionError.builder().type(TYPE).initActivityId(getInitActivityId(errorContext)).deploymentId(((ProcessInstanceImpl) nodeInstance.getProcessInstance()).getDeploymentId()).processInstanceId(nodeInstance.getProcessInstance().getId()).processId(nodeInstance.getProcessInstance().getProcessId()).activityId(nodeInstance.getId()).activityName(nodeName(nodeInstance)).jobId(exception.getJobId()).message(exception.getMessage()).error(stacktrace).errorDate(new Date()).build();
}
Aggregations