Referring to my earlier post on Parallel Data Export. One of the follow up questions was about extending the logic to check all running export jobs. If you are triggering more than one job in your groovy script and you are intending to monitor all the jobs’ status, this post is about you.

List<String> jobRunIds = []
...
HttpResponse<String> jsonResponse = operation.application.getConnection("MyConnection").post("/jobs").body(body).asString();
ctx = JsonPath.parse(jsonResponse.body)
jobRunIds.add(ctx.read('$.jobId').toString())

Basic idea here is to create a list of job IDs and refer to this list later in the code to identify their status. jobRunIds in this example is the list that we are using. Once a job is triggered using MyConnection, it is possible to capture jobID created in your EPM Cloud application. By using add method of the list jobRunIds we can simply add the job ID just created to our list.

final int IN_PROGRESS = -1;
int status = IN_PROGRESS
for(long delay = 50; status == IN_PROGRESS; delay = Math.min(1000, delay * 2)) {
         sleep(delay)
         status = 0
         jobRunIds.each{
            HttpResponse<String> pingResponse = operation.application.getConnection("MyConnection").get("/jobs/$it").asString()
            int statusjob = JsonPath.parse(pingResponse.body).read('$.status');
            if(statusjob == IN_PROGRESS){ status=IN_PROGRESS }
         }
    } 

We need to create a mechanism to capture status of each job and make sure all jobs are completed before proceeding for the rest of the code. By reading the status code, you can interpret whether the job has been completed or still in progress. jobRunIds.each Loop in this example runs until all the jobs in the list jobRunIds are completed.

jobRunIds.each{
            HttpResponse<String> pingResponse = operation.application.getConnection("MyConnection").get("/jobs/$it").asString()
            int statusjob = JsonPath.parse(pingResponse.body).read('$.status');
            println("status for $it : " + statusjob)
            if(statusjob != 0){ 
                throwVetoException("Error occured: At least one job has failed") 
             }

For the final part of the code, you may want to check whether all the jobs are completed successfully. This example checks all the jobs in list jobRunIds. Status has to be 0 for the job to indicate it has been completed successfully. If any of the jobs in our list is completed with a status other that 0, we may want to fail the rule with throwVetoException command.

LEAVE A REPLY

Please enter your comment!
Please enter your name here