Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
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
Employee Advisor

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

Employee Advisor

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
Employee Advisor

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.