Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Define Quartz scheduler beans inside the add-on #53

Closed
gorbunkov opened this issue Jun 9, 2021 · 0 comments
Closed

Define Quartz scheduler beans inside the add-on #53

gorbunkov opened this issue Jun 9, 2021 · 0 comments
Assignees
Milestone

Comments

@gorbunkov
Copy link
Contributor

gorbunkov commented Jun 9, 2021

The search add-on requires a scheduler for processing the indexing queue. Currently we recommend users to add the spring-boot-starter-quartz to their project and to define all quartz beans in projects. Probably we can simplify the process by doing the following:

  1. Define a compile-time dependency to the quartz in the add-on

  2. Create an auto-configuration that will instantiate required quartz beans if quartz is in the classpath and if a special application property is set, e.g. jmix.search.useDefaultIndexingQueueProcessingQuartzConfiguration is true (default behavior).

The Quartz beans:

public class IndexingQueueProcessingJob implements Job {

    @Autowired
    private IndexingQueueManager indexingQueueManager;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
          indexingQueueManager.processNextBatch();
    }
}

@Bean
JobDetail indexingQueueProcessingJob() {
	return JobBuilder.newJob()
			.ofType(IndexingQueueProcessingJob.class)
			.storeDurably()
			.withIdentity("IndexingQueueProcessing")
			.build();
}

@Bean
Trigger indexingQueueProcessingTrigger() {
	return TriggerBuilder.newTrigger()
			.forJob(indexingQueueProcessingJob())
			.startNow()
			.withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
			.build();
}
  1. The cron expression should be taken from the application property, e.g. jmix.search.indexingQueueProcessingCron
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants