Skip to content

Commit 34a2519

Browse files
A few enhancements to make server admin easier
1 parent d862bf1 commit 34a2519

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

nextflow/src/org/labkey/nextflow/pipeline/NextFlowPipelineJob.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
import lombok.Getter;
44
import org.apache.commons.lang3.StringUtils;
5+
import org.apache.logging.log4j.Logger;
56
import org.jetbrains.annotations.NotNull;
7+
import org.json.JSONObject;
68
import org.labkey.api.data.Container;
79
import org.labkey.api.files.FileContentService;
810
import org.labkey.api.pipeline.ParamParser;
911
import org.labkey.api.pipeline.PipeRoot;
1012
import org.labkey.api.pipeline.PipelineJobService;
13+
import org.labkey.api.pipeline.PipelineService;
14+
import org.labkey.api.pipeline.PipelineStatusFile;
1115
import org.labkey.api.pipeline.TaskId;
1216
import org.labkey.api.pipeline.TaskPipeline;
1317
import org.labkey.api.pipeline.file.AbstractFileAnalysisJob;
1418
import org.labkey.api.util.FileUtil;
1519
import org.labkey.api.util.PageFlowUtil;
20+
import org.labkey.api.util.StringUtilsLabKey;
21+
import org.labkey.api.util.logging.LogHelper;
1622
import org.labkey.api.view.ViewBackgroundInfo;
1723

1824
import java.io.BufferedWriter;
@@ -26,6 +32,8 @@
2632
@Getter
2733
public class NextFlowPipelineJob extends AbstractFileAnalysisJob
2834
{
35+
protected static final Logger LOG = LogHelper.getLogger(NextFlowPipelineJob.class, "NextFlow jobs");
36+
2937
private Path config;
3038

3139
@SuppressWarnings("unused") // For serialization
@@ -51,6 +59,24 @@ public NextFlowPipelineJob(ViewBackgroundInfo info, @NotNull PipeRoot root, Path
5159
super(new NextFlowProtocol(), NextFlowPipelineProvider.NAME, info, root, config.getFileName().toString(), config, inputFiles, false, false);
5260
this.config = config;
5361
setLogFile(log);
62+
LOG.info("NextFlow job queued: {}", getJsonJobInfo());
63+
}
64+
65+
protected JSONObject getJsonJobInfo()
66+
{
67+
JSONObject result = new JSONObject();
68+
result.put("user", getUser().getEmail());
69+
result.put("container", getContainer().getPath());
70+
result.put("filePath", getLogFilePath().getParent().toString());
71+
result.put("runName", getNextFlowRunName());
72+
result.put("configFile", getConfig().getFileName().toString());
73+
return result;
74+
}
75+
76+
protected String getNextFlowRunName()
77+
{
78+
PipelineStatusFile file = PipelineService.get().getStatusFile(getJobGUID());
79+
return file == null ? "Unknown" : ("LabKeyJob" + file.getRowId());
5480
}
5581

5682
@Override
@@ -87,7 +113,7 @@ private static Path createConfig(Path configTemplate, Path parentDir, Path jobDi
87113
@Override
88114
public String getDescription()
89115
{
90-
return "NextFlow analysis using " + config.getFileName() + " of " + getInputFilePaths().size() + " files";
116+
return "NextFlow analysis of " + StringUtilsLabKey.pluralize(getInputFilePaths().size(), "file") + " using config: " + config.getFileName();
91117
}
92118

93119
@Override

nextflow/src/org/labkey/nextflow/pipeline/NextFlowRunTask.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public NextFlowRunTask(Factory factory, PipelineJob job)
4242
super(factory, job);
4343
}
4444

45-
46-
4745
@Override
4846
public @NotNull RecordedActionSet run() throws PipelineJobException
4947
{
5048
Logger log = getJob().getLogger();
49+
NextFlowPipelineJob.LOG.info("Starting to execute NextFlow: {}", getJob().getJsonJobInfo());
5150

5251
SecurityManager.TransformSession session = null;
52+
boolean success = false;
5353

5454
try
5555
{
@@ -69,13 +69,14 @@ public NextFlowRunTask(Factory factory, PipelineJob job)
6969

7070
// Need to pass to the main process directly in the future to allow concurrent execution for different users
7171
ProcessBuilder secretsPB = new ProcessBuilder("nextflow", "secrets", "set", "PANORAMA_API_KEY", apiKey);
72-
log.info("Job Started");
72+
log.info("Setting secrets");
7373
File dir = getJob().getLogFile().getParentFile();
7474
getJob().runSubProcess(secretsPB, dir);
7575

7676
ProcessBuilder executionPB = new ProcessBuilder(getArgs());
7777
getJob().runSubProcess(executionPB, dir);
7878
log.info("Job Finished");
79+
NextFlowPipelineJob.LOG.info("Finished executing NextFlow: {}", getJob().getJsonJobInfo());
7980

8081
RecordedAction action = new RecordedAction(ACTION_NAME);
8182
for (Path inputFile : getJob().getInputFilePaths())
@@ -84,6 +85,7 @@ public NextFlowRunTask(Factory factory, PipelineJob job)
8485
}
8586
addOutputs(action, getJob().getLogFilePath().getParent().resolve("reports"), log);
8687
addOutputs(action, getJob().getLogFilePath().getParent().resolve("results"), log);
88+
success = true;
8789
return new RecordedActionSet(action);
8890
}
8991
catch (IOException e)
@@ -96,6 +98,10 @@ public NextFlowRunTask(Factory factory, PipelineJob job)
9698
{
9799
session.close();
98100
}
101+
if (!success)
102+
{
103+
NextFlowPipelineJob.LOG.info("Failed executing NextFlow: {}", getJob().getJsonJobInfo());
104+
}
99105
}
100106
}
101107

@@ -182,6 +188,8 @@ private boolean hasAwsSection(Path configFile) throws PipelineJobException
182188
}
183189
args.add("-c");
184190
args.add(configFile.toAbsolutePath().toString());
191+
args.add("-name");
192+
args.add(getJob().getNextFlowRunName());
185193
return args;
186194
}
187195

0 commit comments

Comments
 (0)