Hi, I need to create a scheduler which runs every 15 minutes. Is it possible using flowable ?
I’m not familiar with flowable. Can someone help me how to do this ?
Hello.
I will try to help you with a sample from a project, but as I’m busy, I will simple share the code and I hope it will make sense for you.
The job class:
package br.com.dgcloud.flowable.jobs;
@Component
public class MiEndTasksCleanupJobHandler {@Value(“${MiEndTasksCleanupJobHandler.dryrun}”)
Boolean dryRun;@Scheduled(cron = “${MiEndTasksCleanupJobHandler.cronexpresion}”)
public void execute() {
HistoryService hs = ProcessEngines.getDefaultProcessEngine().getHistoryService();
List tasks = hs.createHistoricTaskInstanceQuery().taskDeleteReason(“MI_END”).list();for (HistoricTaskInstance task : tasks) { String taskDescription = task.getDescription(); if (dryRun != null && !dryRun) { hs.deleteHistoricTaskInstance(task.getId()); } };
}
}
For the configuration, I have the following properties in the applications.properties file:
MiEndTasksCleanupJobHandler.cronexpresion=0 0/5 8-19 * * MON-FRI
MiEndTasksCleanupJobHandler.dryrun=false
And of course, I have spring configured to read my project’s classes by using the spring.factories file with the following content:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=br.com.dgcloud.flowable.MyCustomCustomEngineConfiguration
And the configuration class is:
package br.com.dgcloud.flowable;
@Primary
@Configuration
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
@AutoConfigureAfter(ProcessEngineAutoConfiguration.class)
@EnableScheduling
@ComponentScan(basePackageClasses = MyCustomEngineConfiguration.class)
public class MyCustomEngineConfiguration {
// not usefull code for this answer got removed
}
Thank You for spending your valuable time and sharing sample code. I will try out this.
@douglascrp How do I get the current running instance in the job handler ?
Note that the code shared by @douglascrp uses Spring to schedule logic to be repeated, not a Flowable Job handler. It will indeed periodically execute the logic. Just making sure everyone is on the same page here :-).
Can you elaborate what you’re trying to achieve? What ‘instance’ do you want?
Setting up a scheduler every 15 minutes is definitely doable with Flowable. I remember when I first tackled something similar for a project using another BPMN engine. The key is understanding how to configure periodic jobs within Flowable’s scheduler or integrating it with an external scheduler like cron for precise timing.