Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM 6.1 Sling Jobs unscheduling

Avatar

Level 2

Hi I am trying to unschedule the sling jobs(Scheduled jobs) in aem 6.1 programmatically.

Its not working. I am using below method.

public void stopScheduledJob() {

Collection<ScheduledJobInfo> myJobs = jobManager.getScheduledJobs(TOPIC, 10, null); myJobs.foreach(sji -> sji.unschedule());

}

 

Please let me know, is there any other solution apart from this.

 

PS: I dont want to delete manually under /var/eventing/scheduled-jobs

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @KaustubaTM , 

 

You can try finding job using 

 

 

Job getJob(java.lang.String topic, java.util.Map<java.lang.String,java.lang.Object> template)
Find a job - either queued or active.

 

Once you have job, you can get the Job id from that job 

 

java.lang.String getId()
Unique job ID.

 

Then stop or remove that job using job id

 

void stopJobById(java.lang.String jobId)
Stop a job.
boolean removeJobById(java.lang.String jobId)
Removes the job even if it is currently in processing.

View solution in original post

3 Replies

Avatar

Level 2

hi @KaustubaTM , If you are using any cron expression to schedule your sling job then you can try changing cron expression to unschedule it.

Avatar

Level 2

Hi Nikita,

I am using below method to schedule. if I change the cron param, it will create a new job with new time

 

ScheduleBuilder scheduleBuilder = jobManager.createJob(TOPIC).schedule();
scheduleBuilder.daily(21, 00);

Avatar

Correct answer by
Level 2

Hi @KaustubaTM , 

 

You can try finding job using 

 

 

Job getJob(java.lang.String topic, java.util.Map<java.lang.String,java.lang.Object> template)
Find a job - either queued or active.

 

Once you have job, you can get the Job id from that job 

 

java.lang.String getId()
Unique job ID.

 

Then stop or remove that job using job id

 

void stopJobById(java.lang.String jobId)
Stop a job.
boolean removeJobById(java.lang.String jobId)
Removes the job even if it is currently in processing.