AEM 6.1 Sling Jobs unscheduling | Community
Skip to main content
Level 2
November 24, 2022
Solved

AEM 6.1 Sling Jobs unscheduling

  • November 24, 2022
  • 1 reply
  • 1527 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nikita___Garg

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.

1 reply

Adobe Employee
November 24, 2022

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

Level 2
November 24, 2022

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);

Nikita___GargAdobe EmployeeAccepted solution
Adobe Employee
November 24, 2022

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.