Skip to content

Commit

Permalink
Merge pull request #9 from compgen-io/show_pending
Browse files Browse the repository at this point in the history
Added show-pending command
  • Loading branch information
mbreese committed Feb 23, 2022
2 parents 33f67bd + f41d742 commit f37aaa5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/java/io/compgen/cgpipe/CGPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.commons.logging.LogFactory;

import io.compgen.cgpipe.cmd.CancelPending;
import io.compgen.cgpipe.cmd.ShowPending;
import io.compgen.cgpipe.cmd.UpdateJobEnd;
import io.compgen.cgpipe.cmd.UpdateJobStart;
import io.compgen.cgpipe.cmd.Vaccuum;
Expand Down Expand Up @@ -88,6 +89,15 @@ public static void main(String[] args) throws Exception {
return;
}

if (args.length > 0 && args[0].equals("show-pending")) {
String [] newargs = new String[args.length-1];
for (int i=1; i< args.length; i++) {
newargs[i-1] = args[i];
}
ShowPending.main(newargs);
return;
}

defaultMain(args);
}

Expand Down
69 changes: 69 additions & 0 deletions src/java/io/compgen/cgpipe/cmd/ShowPending.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.compgen.cgpipe.cmd;

import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;

import io.compgen.cgpipe.CGPipe;
import io.compgen.cgpipe.exceptions.ASTExecException;
import io.compgen.cgpipe.exceptions.ASTParseException;
import io.compgen.cgpipe.exceptions.RunnerException;
import io.compgen.cgpipe.parser.context.RootContext;
import io.compgen.cgpipe.runner.JobRunner;
import io.compgen.cgpipe.runner.joblog.JobLog;
import io.compgen.cgpipe.support.SimpleFileLoggerImpl;
import io.compgen.cmdline.MainBuilder;
import io.compgen.cmdline.annotation.Command;
import io.compgen.cmdline.annotation.Exec;
import io.compgen.cmdline.annotation.UnnamedArg;
import io.compgen.cmdline.impl.AbstractCommand;
import io.compgen.common.StringUtils;

@Command(name = "cgpipe show-pending", desc = "Show any pending (or running) jobs. Requires cgpipe.runner to be set (in cgpiperc, etc)", doc = "")
public class ShowPending extends AbstractCommand {
private String jobLogFilename = null;

@UnnamedArg(required = true, name="FILE")
public void setJobLogFilename(final String jobLogFilename) {
this.jobLogFilename = jobLogFilename;
}

@Exec
public void exec() throws IOException, ASTParseException, ASTExecException, RunnerException {
SimpleFileLoggerImpl.setSilent(true);
JobRunner runner = null;
// Load config values from global config.
RootContext root = new RootContext();
root.setOutputStream(null);
CGPipe.loadInitFiles(root);


// Load the job runner *after* we execute the script to capture any config changes
runner = JobRunner.load(root);

JobLog log = JobLog.open(jobLogFilename);

// <JobId, Output>
Map<String, String> jobs = new TreeMap<String, String> (StringUtils.naturalSorter());

for (String output: log.getOutputJobIds().keySet()) {
String jobid = log.getJobIdForOutput(output);
if (jobs.containsKey(jobid)) {
jobs.put(jobid, jobs.get(jobid)+","+output);
} else {
jobs.put(jobid, output);
}
}


for (String jobid: jobs.keySet()) {
if (runner.isJobIdValid(jobid)) {
System.out.println(jobid + ": " + jobs.get(jobid));
}
}
}

public static void main(final String[] args) throws Exception {
new MainBuilder().runClass(CancelPending.class, args);
}
}

0 comments on commit f37aaa5

Please sign in to comment.