Skip to content

Scheduled job

Erich Jagomägis edited this page Nov 14, 2023 · 1 revision

Introducing a more convenient way of creating scheduled jobs and reduces boilerplate code.

Requirements

This feature requires the presence of SchedulerTraceIdResolver bean in the context. That bean is auto-configured with Trace ID auto-configuration.

Usage

Given that your unit of work is defined as feature or command, you need to implement ee.bitweb.core.scheduled.ScheduledRunnable interface. That interface will allow you to define how you want to invoke your scheduled job.

After, you have to define an invocation class for your scheduled job. That class should reside in the api layer of your project. Invocation class should extend ee.bitweb.core.scheduled.ScheduledJob class.

In that class run() method will execute the cron job along with error handling, logging and Trace ID management. Class can adapt it to your scheduling library.

Sample

    @Component
    public class ProductionOrderUpdateScheduler extends ScheduledJob<ProductionOrderRowImportComponent> {
    
        public ProductionOrderUpdateScheduler(
            final ProductionOrderRowImportComponent runnable,
            final SchedulerTraceIdResolver traceIdResolver
        ) {
            super(runnable, traceIdResolver);
        }
    
        @Scheduled(cron = "${scheduled.production-order-row.cron}")
        public void schedule() {
            run();
        }
    }

Clone this wiki locally