View sling job status programatically for the completed jobs | Community
Skip to main content
Level 2
November 17, 2023
Solved

View sling job status programatically for the completed jobs

  • November 17, 2023
  • 3 replies
  • 2190 views

Not able to view JobStatus of completed jobs.

Tried these steps but not working: 

jobManager.getJobById(jobId)

jobManager.findJobs(JobManager.QueryType.ALL, TEST_JOB_TOPIC, -1);

 

This returns only the failed or GIVEN_UP status ones

jobManager.findJobs(JobManager.QueryType.HISTORY, TEST_JOB_TOPIC, -1)

 

AEM version AEM 6.5.15

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 samaraneni

From what I hear, as JobManager currently DOES NOT retain any completed jobs the workaround is we store the job and use it for retrieval. Thanks

3 replies

aanchal-sikka
Community Advisor
Community Advisor
November 18, 2023

@samaraneni 

 

Can you please try with following code?

Collection<Job> succeededJobs = jobManager.findJobs(JobManager.QueryType.SUCCEEDED, topic, 100, (Map<String, Object>[]) null);
Aanchal Sikka
Level 2
November 19, 2023

Still the same null. Although I have succeeded jobs, the only QueryType value that gives values is GIVEN_UP. Is it because the current jobmanager configuration does not keep track of the completed jobs but only keeps track of the GIVEN_UP(retried ones) ? If so could you please guide me with any configuration change that would be required.

ShaileshBassi
Community Advisor
Community Advisor
November 19, 2023

Hi @samaraneni IMO, you can try out using the API i.e. TopicStatistics.

Reference - https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/sling/event/jobs/TopicStatistics.html

This has the method i.e. getNumberOfProcessedJobs() to get the no of processed jobs for a particular job topic.

Hope this helps!

Thanks

 

partyush
Community Advisor
Community Advisor
November 20, 2023

Hi @samaraneni 

In AEM 6.5, the JobManager API primarily focuses on ongoing or failed jobs, and completed jobs are often not retained for direct querying through the JobManager.

If you specifically need to capture the status of completed jobs, one option is to implement a custom solution:

  1. Custom JobProcessor: In your JobProcessor implementation, after successfully processing the job, log the relevant details or store them in a custom location.

 

 

void process(Job job) { try { // Your job processing logic // Log successful completion log.info("Job {} completed successfully", job.getId()); // Store job details or status in a custom location storeJobDetails(job); } catch (Exception e) { // Log failure log.error("Job {} failed: {}", job.getId(), e.getMessage(), e); } }​

 

 

  • Custom Storage for Job Details: Implement a custom mechanism to store job details or status in a dedicated node in the repository, database, or external storage.

 

 

void storeJobDetails(Job job) { // Implement logic to store job details, e.g., in a custom node in the repository }​

 

 

  • Retrieve Status Programmatically: When you need to retrieve the status of a completed job, query your custom storage instead of relying solely on the JobManager.

 

 

String jobStatus = retrieveJobStatus(jobId);

 

 

Implement the retrieveJobStatus method to query your custom storage for the status of a specific job ID.

 

Hope this information is going to help you ! 

kautuk_sahni
Community Manager
Community Manager
November 20, 2023

@samaraneni Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni
samaraneniAuthorAccepted solution
Level 2
November 22, 2023

From what I hear, as JobManager currently DOES NOT retain any completed jobs the workaround is we store the job and use it for retrieval. Thanks