cancel
Showing results for 
Search instead for 
Did you mean: 

Exception handling for Async executor

nixikanius
Champ in-the-making
Champ in-the-making
I want to implement global exception handling like it suggested to do for Job executor (http://flaviodonze.blogspot.ru/2013/04/activiti-overall-exception-handlingin.html). To do this I added configuration in activiti-custom-context.xml for activiti-rest:


<?xml version="1.0" encoding="UTF-8"?>
<beans …>
  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="failedJobCommandFactory">
          <bean class="org.test.commandFactories.FailedJobCommandFactory" />
        </property>
  </bean>
</beans>


And my test handler on groovy looks like:


package org.test.commandFactories

import org.activiti.engine.impl.jobexecutor.FailedJobCommandFactory;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;

public class JobCommand implements Command<Object> {
private String jobId;
private Throwable exception;

def public JobCommand(String jobId, Throwable exception) {
  this.jobId = jobId;
  this.exception = exception;
}

@Override
def public Object execute(CommandContext commandContext) {
   println "HELLO2!"
}
}

public class FailedJobCommandFactory implements FailedJobCommandFactory {
  @Override
  def public Command<Object> getCommand(String jobId, Throwable exception) {
    println "HELLO1!"
    return new JobCommand(jobId, exception);
  }
}


But when I test exception handling I do not see any "HELLO1!" or "HELLO2!" in catalina logs. Meanwhile if I turn on Job executor everything works fine. Is there any way to handle exceptions the same way for async executor?
3 REPLIES 3

nixikanius
Champ in-the-making
Champ in-the-making
Anybody can help me? I see in sources there is support for custom error handler:

<code>
CommandConfig commandConfig = commandExecutor.getDefaultConfig().transactionRequiresNew();
        FailedJobCommandFactory failedJobCommandFactory = commandContext.getFailedJobCommandFactory();
        Command<Object> cmd = failedJobCommandFactory.getCommand(job.getId(), exception);

        log.trace("Using FailedJobCommandFactory '" + failedJobCommandFactory.getClass() + "' and command of type '" + cmd.getClass() + "'");
</code>

But it does not work. In enabled trace level log I do not see any "Using FailedJobCommandFactory" string even using default error handling.

cjose
Elite Collaborator
Elite Collaborator
I just tested your code by turning on the old job executor
<code>
<property name="jobExecutorActivate" value="true" />
</code>
as well as the new Async Executor
<code>
<property name="asyncExecutorEnabled" value="true" />
<property name="asyncExecutorActivate" value="true" />
</code>

In both cases it is behaving correctly where I can see HELLO1! & HELLO2! getting printed in logs.

Regards,
Ciju

nixikanius
Champ in-the-making
Champ in-the-making
cjose, thank you for you answer! With asyncExecutorActivate it work perfectly.

Meanwhile I do not understand how task processing works if I do not activate Job Executor and do not activate Async Executor. As I see everything works perfectly except custom error handling. Why does it happen? I thought that Job Executor is activated by default.