Hello! The best documentation I can find is here: https://developer.atlassian.com/server/jira/platform/developing-for-high-availability-and-clustering/
I think this is up to date and correct. I copied an example from a plugin we use inside my company:
package com.mycompany;
import com.atlassian.scheduler.*;
import com.atlassian.scheduler.config.JobConfig;
import com.atlassian.scheduler.config.JobId;
import com.atlassian.scheduler.config.JobRunnerKey;
import com.atlassian.scheduler.config.Schedule;
import org.joda.time.DateTime;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.Date;
import static com.atlassian.scheduler.config.JobConfig.forJobRunnerKey;
import static com.atlassian.scheduler.config.RunMode.RUN_ONCE_PER_CLUSTER;
import static java.util.concurrent.TimeUnit.DAYS;
/**
* This is a class I deleted a bunch of stuff from to show as an example. It registers a
* particular type of scheduled task in Jira.
*/
@Named
public class MyClassChangeMe implements JobRunner, InitializingBean, DisposableBean {
private final static String IDENTIFIER = MyClassChangeMe.class.getName();
private final static JobRunnerKey JOB_RUNNER_KEY = JobRunnerKey.of(IDENTIFIER);
private final static JobId JOB_ID = JobId.of(IDENTIFIER);
@ComponentImport
private final SchedulerService schedulerService;
@Inject
public MyClassChangeMe(SchedulerService schedulerService) {
this.schedulerService = schedulerService;
}
@Nullable
@Override
public JobRunnerResponse runJob(@Nonnull JobRunnerRequest jobRunnerRequest) {
return JobRunnerResponse.success("Success");
}
@Override
public void destroy() throws Exception {
schedulerService.unscheduleJob(JOB_ID);
}
@Override
public void afterPropertiesSet() throws Exception {
schedulerService.registerJobRunner(JOB_RUNNER_KEY, this);
final JobConfig configuration = forJobRunnerKey(JOB_RUNNER_KEY)
.withRunMode(RUN_ONCE_PER_CLUSTER)
.withSchedule(Schedule.forInterval(DAYS.toMillis(1), new DateTime()
.withTimeAtStartOfDay()
.plusDays(1)
.plusMinutes(30)
.toDate()));
try {
schedulerService.scheduleJob(JOB_ID, configuration);
} catch (SchedulerServiceException e) {
e.printStackTrace();
}
}
}