x
login Signup

Query for most recent procedure name and status of its respective steps

I want to run a query that is given the procedure name, and will output the most recent run of it (whether it is running now or previous, but the most recent one) with the status of each step. What is the best way to do this and how can it be done?

avatar image By zc5 23 asked Dec 23, 2014 at 05:31 PM
more ▼
(comments are locked)
10|750 characters needed characters left

1 answer: sort voted first

The easiest way to do something like this is to use the EC web UI to define a search. Click on the Search tab that's at the top of most EC pages and then fill in what you want to find:

alt text

You can also save this search as a Shortcut on your EC home page.

If you absolutely want to have a programmatic way to find this information, you can use the EC Perl API to get it. You can use the following code as a starting point.

 use strict;
 use warnings;
 use ElectricCommander;
 
 # init Commander object
 my $ec = new ElectricCommander;
 
 my $proc_name = "some_procedure";
 my $proj_name = "some_project";
 
 my $ec_job;
 eval {
   $ec_job = $ec->findObjects("job",
   {
     maxIds     => "1",
     numObjects => "1",
     filter => [{propertyName => "procedureName",
                 operator     => "equals",
                 operand1     => "$proc_name"},
                {propertyName => "projectName",
                 operator     => "equals",
                 operand1     => "$proj_name"}],
     sort   => [{propertyName => "createTime",
                 order        => "descending"}],
   });
 };
 if($@)
 {
     print "   error from findObjects: $@";
     exit;
 }
 
 my @jobs = $ec_job->findnodes("//object/job");
 if($#jobs < 0) # may be empty
 {
     print "   no jobs have run $proc_name\n";
     exit;
 }
 
 # should be only one job, since that's what we asked for
 #  but in case you want more, here's a loop
 foreach my $j (@jobs)
 {
     my $jobId = $j->findvalue("jobId")->value;
     print "jobId: $jobId\n";
     my $jobName = $j->findvalue("jobName")->value;
     print "jobName:  $jobName\n";
     my $job_outcome = $j->findvalue("outcome")->value;
     print "job outcome:  $job_outcome\n";
     my $procedureName = $j->findvalue("procedureName")->value;
     print "procedureName:  $procedureName\n";
     my $job_status = $j->findvalue("status")->value;
     print "job status: $job_status\n";
 
     my $ec_jd = $ec->getJobDetails($jobId);
 
     my @steps = $ec_jd->findnodes("//jobStep");
 
     foreach my $s (@steps)
     {
         my $stepName = $s->findvalue("stepName")->value;
         my $step_outcome = $s->findvalue("outcome")->value;
         my $step_status = $s->findvalue("status")->value;
         print " stepName $stepName:\n";
         print "   outcome $step_outcome\n";
         print "   status $step_status\n";
     }
 }

Remember that Ask likes to put extra backslashes in code examples, so be sure to remove them before using the code above.

avatar image By sbarry 1.5k answered Dec 23, 2014 at 07:57 PM
more ▼
(comments are locked)
10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.