quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.74k stars 2.67k forks source link

To add support for non-concurrent task execution in a clustered environment #44048

Open vondacho opened 2 hours ago

vondacho commented 2 hours ago

Description

Considering a clustered setup of Quartz and the need for a recurrent task to be triggered only once its previous execution is terminated, can be addressed using the programmatic way i.e. the Quartz API.

final JobDetail job = JobBuilder.newJob(MyTask.class).withIdentity(identity, group).build();
final Trigger trigger = TriggerBuilder.newTrigger()
        .withIdentity(identity, group)
        .withSchedule(CronScheduleBuilder.cronSchedule(cron))
        .build();
scheduler.schedule(job, trigger);

@DisallowConcurrentExecution
public static final class MyTask implements Job {
    @Override
    public void execute(JobExecutionContext context) {
        // my work
    }
}

The declarative way i.e. the @Scheduled annotation is still limited, because its concurrentExecution attribute manages non-concurrency locally on a single node i.e. a single application instance, but not globally, considering every nodes i.e. every application instances.

Therefore, the request is to provide an equivalent solution design using the declarative way i.e. an annotation like the @Scheduled one.

Implementation ideas

geoand commented 1 hour ago

cc @mkouba