cancel
Showing results for 
Search instead for 
Did you mean: 

What happens to unhandled exceptions in service task

eduardp
Champ in-the-making
Champ in-the-making
Hi

I created a simple process that has a service task that calls a java class that just throws a RuntimeException. This is followed by an empty user task.

I basically want to know what would happen in this case and how to recover from the situation. Let's say for example my java code tried to access a database, but the database was down,  I'd like to see somewhere on the interface what the exception was and I'd like to 'resubmit' the process instance to the same step once the database is up again. How can I achieve this?

In my test, when the exception if thrown, the process instance moves to the Archived node on the explorer interface. I see no way of re-submitting the task, or a place where I can see the exception stack trace (apart for the log file).

If I'm on the wrong track, please let me know what the 'best practice' for this scenario is.

Thanks!
Eduard
3 REPLIES 3

meyerd
Champ on-the-rise
Champ on-the-rise
You could try making the serviceTask asynchronous:
http://activiti.org/userguide/index.html#asyncContinuations

That way activiti would commit the transaction before calling the service and if calling the service fails, activiti will retry calling the service periodically.

In order to really understand this, make sure you understand what the JobExecutor does.

Does that help?

eduardp
Champ in-the-making
Champ in-the-making
Hi

I'll have a look at the JobExecutor.
What would be nice though is some functionality where I can specify declaratively what should happen on service task failure - for example "on error forward the task to the sysAdmin Group".

Also I'm not to sure how usefull automatic retry is on a service task. Let's say I do some heavy processing in a java class that ends up throwing an exception. With automatic retry, this might cause it to just happen again on every retry. It would be beter if the task could "go somewhere else" while the problem is being fixed and then be "resubmitted" later.

I could probably model something like this in a sub process, but it would be nice to have the engine cater for it, because I can imagine myself needing this functionality for every service task

Regards
Eduard

meyerd
Champ on-the-rise
Champ on-the-rise
What would be nice though is some functionality where I can specify declaratively what should happen on service task failure - for example "on error forward the task to the sysAdmin Group".
Well in that case you have to decide what "error" means. Does it mean the java code associated with the serviceTask throws an exception?

Also I'm not to sure how usefull automatic retry is on a service task. Let's say I do some heavy processing in a java class that ends up throwing an exception. With automatic retry, this might cause it to just happen again on every retry. It would be beter if the task could "go somewhere else" while the problem is being fixed and then be "resubmitted" later.

I could probably model something like this in a sub process, but it would be nice to have the engine cater for it, because I can imagine myself needing this functionality for every service task

In activiti you can change the semantics of the serviceTask in the sense that you can implement your own org.activiti.engine.impl.pvm.delegate.ActivityBehavior instead of JavaDelegate. In ActivitiyBehavior you are also responsible for leaving the current activity. Think twice about it though: this is internal API.

Quote from the User-Guide:
It is also possible to provide a class that implements the org.activiti.engine.impl.pvm.delegate.ActivityBehavior interface. Implementations have then access to the more powerful ActivityExecution that for example also allows to influence the control flow of the process. Note however that this is not a very good practice, and should be avoided as much as possible. So, it is advised to use the ActivityBehavior interface only for advanced use cases and if you know exactly what you're doing.