cancel
Showing results for 
Search instead for 
Did you mean: 

Executing Asynchronous Processes from exception point

sankardunga
Champ in-the-making
Champ in-the-making
Hello,

I have multiple service tasks in my process. I'm not able to re-execute the job from exception point of particular task.

I'm using ''managementService.executeJob(id)'' for executing the particular job, here it is executing the process from service task1.

How to run the job from the exeception point of a process ?

Thanks in advance…Smiley Happy


26 REPLIES 26

frederikherema1
Star Contributor
Star Contributor
Depends on where the exception is thrown… It looks like an exception occuring as part of a service-task execution. You won't be able to alter that message. If you use a java-delegate, you can throw any exception you want from within the execute() method.

sankardunga
Champ in-the-making
Champ in-the-making
Thanks frederikheremans.
Ya, I'm trying to throw my own exception in the service task which is not implementing java-delegate.
And here I'm looking for an option to store my custom exception in Database. Isn't it possible at all in activiti without using java-delegate.

Can you please suggest me some approach here ?

trademak
Star Contributor
Star Contributor
Are you using an expression or delegate expression then? If it throws a custom exception, this exception should be stored in the job exception message by default. What do you see in the job exception message?

Best regards,

sankardunga
Champ in-the-making
Champ in-the-making
I'm using expression but not delegate expression. I'm getting following value in ACT_RU_JOB table
                 " Error while evaluating expression: #{createServer .processEvent(data)} "

Here I'm not implementing the JavaDelegate behavior to my class.
My class snippet looks this

     public class CreateServer  extends AbstractHandler {
        @Override
protected void execute(IEvent event)  throws ActivitiException { 
  CreateServer  createServer = null;
  if(event instanceof CreateServer  ){
   createServer = (CreateServer  ) event;
   myMethod(createServer );    //Custom Exception thrown in this method
  }
  }
      }

can I store my custom exception message here ?

frederikherema1
Star Contributor
Star Contributor
The delegate expression will always be executed by JUEL. Any exceptions that occur there will be wrapped. You could use the cause of the exception, found in the referenced stacktrace byte-array entity. However, the exception-message in the ACT_RU_JOB row wil still be the message of the outer JUEL-exception.

An option to modify the message is to override the org.activiti.engine.impl.jobexecutor.DefaultFailedJobCommandFactory class, and return a custom DecrementJobRetriesCmd that populates the exception-message based on what you want. Currently, it does this:


if(exception != null) {
      job.setExceptionMessage(exception.getMessage());
      job.setExceptionStacktrace(getExceptionStacktrace());
    }

Plug your custom implementation of the org.activiti.engine.impl.jobexecutor.DefaultFailedJobCommandFactory in the "failedJobCommandFactory" property of the process engine configuration.

sankardunga
Champ in-the-making
Champ in-the-making
Thanks frederikheremans. Now I gonna ask one poor doubt … Smiley Happy
Do I need to implement 'FailedJobCommandFactory' interface in my exception class to override the "getCommand((jobId, exception)" method ?
Any other configuration is required ?
Please help me where & how can override this class ?

frederikherema1
Star Contributor
Star Contributor
You can extend the DefaultFailedJobCommandFactory and override the getCommand() method, indeed. No other configuration required, other than setting this factory on your configuration.

sankardunga
Champ in-the-making
Champ in-the-making
This is my exception class and I override the "DefaultFailedJobCommandFactory " class.
    public class ValidateUpdateServerRequestException extends DefaultFailedJobCommandFactory {
        private static final long serialVersionUID = -5681708327398999347L;
   public Command<Object> getCommand(String jobId, Throwable exception) {
       return new DecrementJobRetriesCmd(jobId, exception);
   }
    }

How to do factory bean configuration in xml ?
Can please give me example ?

frederikherema1
Star Contributor
Star Contributor
Use the property "failedJobCommandFactory" to set a reference to your factory:


<property name="failedJobCommandFactory">
   <bean class="com.whatever.ValidateUpdateServerRequestException" />
</property>
[code]

sankardunga
Champ in-the-making
Champ in-the-making
Ya, I have override the class & set the configuration. It is coming to the overridden class. But still I'm getting the same 'ActivitiException stacktrace' with Throwable class type parameter of getCommand() method instead of whatever I'm throwing from my class.

I'm not getting from where it is setting this exception ?