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.
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?
조회 수
Likes
답글
조회 수
Likes
답글