cancel
Showing results for 
Search instead for 
Did you mean: 

Specify delayTime at startup ?

stroobat
Champ in-the-making
Champ in-the-making
Is there an option somewhere to specify a delay time before the jobExecutor starts the polling process ?

Best regards,

Tom.
15 REPLIES 15

njames
Champ in-the-making
Champ in-the-making
I don't know if this scenario was outlined in this thread, but I have a similar need. I have a number of executions waiting on timer boundary events in the activiti database. When I start my activiti engine, the job executor fires some of these executions during the application start up. Unfortunately, these processes use Camel routes and my camel routes haven't started before the job executor is enabled. Hence all my stored executions crash.
I would like to have all the Camel routes and everything configured and working before the job executor comes alive.
Nick.

jbarrez
Star Contributor
Star Contributor
I see your problem, but I don't know if a 'delay' attribute is the solution. After all, you can never know how long it will take next time it will take for the engine to boot….

If you are using spring, as in the Jira issue above, there is a already a solution proposed which allows you to do that.

Anybody has a suggestion on how to know when the executor is safe to start?

jdev_hari
Champ in-the-making
Champ in-the-making
We are facing the issue as mentioned above in a multi-node cluster. I am thinking of a full blown solution as follows

- set jobexecutor as false in activiti configuration file
- have a topic and listener configured from every jvm
- once server starts, we will have someone click to openup the workflow engine (it places a message in topic, the listener would start the jobexecutor)

A cleaner solution would avoid having all these lot of moving parts.

trademak
Star Contributor
Star Contributor
I think that's a good solution to implement the "delay" behavior.

Best regards,

engywook
Champ in-the-making
Champ in-the-making
We went with an event-driven solution to address this problem.  We're using Activiti 5.14 with Spring 3.2 and Camel 2.12.  Our processes rely on Camel routes, so if the JobExecutor starts before the Camel routes have been started, then the jobs will fail. 

First, I tried using Spring's SmartLifecycle to ensure the JobExecutor starts during the last phase.  It did make it start in the last phase of startup, but then I realized that the Camel routes are started upon receiving Spring's ContextRefreshedEvent, which is fired after the spring context has loaded.  So the JobExecutor was still starting prior to the Camel route startup. I only mention this because if you are not using Camel, then the SmartLifecycle approach may work for you.

Since we require the Camel context to have loaded completely before JobExecutor, I added a bean to start the JobExecutor upon receipt of the CamelContextStartedEvent.

<code>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

<property name="jobExecutorActivate" value="false" />
<property name="jobExecutor" ref="jobExecutor"/>

</bean>

<bean id="jobExecutor" class="org.activiti.engine.impl.jobexecutor.DefaultJobExecutor"/>
</code>

<java>
@Named
public class JobExecutorStarter extends EventNotifierSupport {

@Inject
private JobExecutor jobExecutor;

@Override
public void notify(EventObject event) throws Exception {
  if (event instanceof CamelContextStartedEvent) {
   jobExecutor.start();
  } else if (event instanceof CamelContextStoppingEvent) {
   jobExecutor.shutdown();
  }
 
}

@Override
public boolean isEnabled(EventObject event) {
  return event instanceof CamelContextStartedEvent || event instanceof CamelContextStoppingEvent;
}

@Override
protected void doStart() throws Exception {
}

@Override
protected void doStop() throws Exception {
}

}
</java>

jbarrez
Star Contributor
Star Contributor
Thanks for posting this! Clean solution.