Expand my Community achievements bar.

SOLVED

View sling job status programatically for the completed jobs

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 2

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

View solution in original post

7 Replies

Avatar

Community Advisor

@samaraneni 

 

Can you please try with following code?

Collection<Job> succeededJobs = jobManager.findJobs(JobManager.QueryType.SUCCEEDED, topic, 100, (Map<String, Object>[]) null);

Aanchal Sikka

Avatar

Level 2

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.

Avatar

Community Advisor

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/even...

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

Hope this helps!

Thanks

 

Avatar

Level 2

Hi, the use case is, I'm writing a status monitoring servlet endpoint which takes in a list of jobIds that belong to a topic and returns the status of each. Some of these could be failed and some succeeded. I have hard time finding the status of completed ones, only the failed with the status of GIVEN_UP are available to view. So to achieve this I think getNumberOfProcessedJobs() won't help. Please guide me here

Avatar

Community Advisor

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 ! 

Avatar

Administrator

@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

Avatar

Correct answer by
Level 2

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