Solved
Add delay of 5mins before running the sling job.
Hi,
We have written a listener to run a sling job whenever the asset is modified. Is there a way to add a delay of 5mins to jobManager.addJob() then run the sling job?
Thank you.
Hi,
We have written a listener to run a sling job whenever the asset is modified. Is there a way to add a delay of 5mins to jobManager.addJob() then run the sling job?
Thank you.
You can use Scheduled Jobs, to achieve your goal. Below is a sample code snippet:
import org.apache.sling.event.jobs.JobManager;
import org.apache.sling.event.jobs.JobBuilder.ScheduleBuilder;
import java.util.Calendar;
import java.util.Date;
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
// increasing time by 5 minutes
calendar.add(Calendar.MINUTE, 5);
Date date = calendar.getTime();
ScheduleBuilder scheduleBuilder = jobManager.createJob("your topic").schedule();
scheduleBuilder.at(date);
if (scheduleBuilder.add() == null) {
// something went wrong here, use scheduleBuilder.add(List<String>) instead to get further information about the error
}
In above snippet following things are done:
Using at(Date date) method job will be run once at given time.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.