Exception handling for Async executor

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2016 10:13 AM
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:
And my test handler on groovy looks like:
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?
<?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.commandFactoriesimport 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?
Labels:
- Labels:
-
Archive
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 08:16 AM
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.
<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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2016 02:03 AM
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
<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

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2016 06:14 AM
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.
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.
