Skip to content

Commit

Permalink
Support cloudgene.report.json on step level
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Sep 18, 2023
1 parent 3b26d30 commit 45011a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/main/java/cloudgene/mapred/plugins/nextflow/NextflowStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -16,6 +17,9 @@
import cloudgene.mapred.jobs.CloudgeneStep;
import cloudgene.mapred.jobs.Message;
import cloudgene.mapred.jobs.workspace.IWorkspace;
import cloudgene.mapred.plugins.nextflow.report.Report;
import cloudgene.mapred.plugins.nextflow.report.ReportEvent;
import cloudgene.mapred.plugins.nextflow.report.ReportEventExecutor;
import cloudgene.mapred.util.Settings;
import cloudgene.mapred.wdl.WdlStep;
import genepi.io.FileUtil;
Expand Down Expand Up @@ -152,6 +156,18 @@ public boolean run(WdlStep step, CloudgeneContext context) {

collector.cleanProcesses(context);

File report = new File(executionDir, Report.DEFAULT_FILENAME);
if (!report.exists()) {
return successful;
}

context.log("Load report file from '" + report.getCanonicalPath() + "'");
try {
parseReport(report);
} catch (Exception e) {
log.error("[Job {}] Invalid report file.", e);
}

return successful;

} catch (Exception e) {
Expand All @@ -161,6 +177,15 @@ public boolean run(WdlStep step, CloudgeneContext context) {

}

private void parseReport(File file) throws IOException {
Report report = new Report(file.getAbsolutePath());
context.log("Execute " + report.getEvents().size() + " events.");
for (ReportEvent event : report.getEvents()) {
context.log("Event: " + event);
ReportEventExecutor.execute(event, context);
}
}

@Override
public void updateProgress() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static String format(ReportEvent event) {
}
case MESSAGE: {
String message = (String) event.getParams()[0];
int type = ((Integer) event.getParams()[1]);
int type = asInteger(event.getParams()[1]);
return message(message, type);
}
case BEGIN_TASK: {
Expand All @@ -88,12 +88,12 @@ public static String format(ReportEvent event) {
}
case END_TASK: {
String name = (String) event.getParams()[0];
int type = ((Integer) event.getParams()[1]).intValue();
int type = asInteger(event.getParams()[1]);
return message(name, type);
}
case INC_COUNTER: {
String counter = (String) event.getParams()[0];
int value = ((Integer) event.getParams()[1]);
int value = asInteger(event.getParams()[1]);
return incCounter(counter, value);
}
default:
Expand Down Expand Up @@ -137,5 +137,12 @@ public static String message(String message, int type) {

}
}

public static int asInteger(Object object) {
//groovy writes integers also as doubles
Double value = Double.parseDouble(object.toString());
return value.intValue();

}

}

0 comments on commit 45011a4

Please sign in to comment.