This is related to another ticket I had logged, but in that case it was the syntax flat-out not working. The approach I have got now appears to register my custom job handler, except that the call back never gets fired. I’ve compared this against a spring boot demo I obtained and the sprint boot approach is executing the custom job while my manual attempt ignores it. Not sure what’s going on. The custom job handler looks like this:
public class CustomJobHandler implements JobHandler {
public static final String TYPE = "cutomJobType";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope,CommandContext commandContext) {
CommandContextUtil.getProcessEngineConfiguration(commandContext).getTaskService().complete(taskId, variableMap);
CommandContextUtil.getProcessEngineConfiguration(commandContext).getTaskService().complete(configuration);
}
}
My code for manually registering the custom job looks like this:
public class FlowableEngine {
public FlowableEngine() {}
public ProcessEngine buildEngine(String jdbcUrl, String userName, String password) {
System.out.println("Creating flowable engine");
ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
System.out.println("Created standalone config for engine construction");
BasicDataSource datasource = new BasicDataSource();
datasource.setDriverClassName("oracle.jdbc.OracleDriver");
datasource.setUrl(jdbcUrl);
datasource.setUsername(userName);
datasource.setPassword(password);
config.setDatabaseSchemaUpdate(AbstractEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
config.setDatabaseType(AbstractEngineConfiguration.DATABASE_TYPE_ORACLE);
config.setDataSource(datasource);
config.setAsyncExecutorActivate(true);
System.out.println("Set the configuration");
JobHandler packageJob = new CustomJobHandler();
List<JobHandler> customHandlers = new ArrayList<JobHandler>();
customHandlers.add(packageJob);
config.setCustomJobHandlers(customHandlers);
System.out.println("Registered custom job handlers");
ProcessEngine engine = config.buildProcessEngine();
System.out.println("Created the engine");
return engine;
}
}
And then I have this little bit of code that actually tries to schedule the job and fire it off:
public static void scheduleAsyncJob(ProcessEngine engine, String jobHandlerType, String jobConfig) {
ManagementService managementService = engine.getManagementService();
managementService.executeCommand(new Command<String>() {
public String execute(CommandContext commandContext) {
JobService jobService = CommandContextUtil.getJobService(commandContext);
JobEntity job = jobService.createJob();
job.setJobHandlerType(jobHandlerType);
job.setJobHandlerConfiguration(jobConfig);
jobService.createAsyncJob(job, false);
jobService.scheduleAsyncJob(job);
return "scheduled";
}
});
}
On the spring boot side of things, this is the bean definition that registers the handler:
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
@Bean
public EngineConfigurationConfigurer customEngineConfiguration() {
return engineConfiguration -> {
engineConfiguration.addCustomJobHandler(new CustomJobHandler());
};
}
}
And here’s the service function that fires it off:
public void scheduleTaskUpdate(String taskId) {
managementService.executeCommand(new Command() {
public String execute(CommandContext commandContext) {
JobService jobService = CommandContextUtil.getJobService(commandContext);
JobEntity job = jobService.createJob();
job.setJobHandlerType(CustomJobHandler.TYPE);
job.setJobHandlerConfiguration(taskId);
jobService.createAsyncJob(job, false);
jobService.scheduleAsyncJob(job);
return "scheduled";
}
});
}
The CustomJobHandler.java is the same code, so my only difference bewteen these approaches seems to be how I register the custom job handler. And I cannot figure out what I’m doing wrong with the procedural approach that Spring does differently.