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.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
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.
Maybe you can create a workflow laucher thats wait for 5 min and then executed or queue the job.
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.
Hi @Keerthana_H_N ,
Are you creating sling jobs when an asset is modified?
I assume the Sling job is executed using a Job Consumer, which likely calls a service to perform the desired action.
To manage execution, you can define the queue configuration using the Apache Sling Job Queue Configuration. Set the property: queue.type as ORDERED and queue.maxparallel: as 1 to prevent parallel execution of multiple jobs. This configuration ensures jobs are executed sequentially, avoiding potential conflicts or race conditions.
Could you elaborate on the specific issues you’re facing due to parallel execution of Sling jobs?
Views
Likes
Replies
Views
Likes
Replies