Skip to content

Commit 91b2d38

Browse files
authored
Creates a scijava task linked to the batch job
* adds a synchronous task when a batch job is started * upon task cancellation, the current item is processed. Remaining ones are skipped Unrelated: * updates gitignore to remove intellij specific files * bump parent pom to 31.1.0 This PR depends on the new functionalities added in scijava-common 2.88.0
1 parent 83e719f commit 91b2d38

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.classpath
33
.project
44
.settings/
5+
.idea/

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.scijava</groupId>
77
<artifactId>pom-scijava</artifactId>
8-
<version>27.0.1</version>
8+
<version>31.1.0</version>
99
<relativePath />
1010
</parent>
1111

@@ -83,7 +83,7 @@
8383
<license.excludes>**/scripts/**</license.excludes>
8484

8585
<!-- NB: Fiji ships with scijava-common-2.80.1.jar currently, so we need to adapt as long as no new pom-scijava is released -->
86-
<scijava-common.version>2.80.1</scijava-common.version>
86+
<scijava-common.version>2.88.0</scijava-common.version>
8787

8888
<!-- NB: Deploy releases to the SciJava Maven repository. -->
8989
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

‎src/main/java/org/scijava/batch/ModuleBatchProcessor.java‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import org.scijava.table.Column;
5151
import org.scijava.table.DefaultGenericTable;
5252
import org.scijava.table.Table;
53+
import org.scijava.task.Task;
54+
import org.scijava.task.TaskService;
5355
//import org.scijava.widget.FileWidget;
5456

5557
@Plugin(type = Command.class, label = "Choose batch processing parameters", initializer = "initInputChoice")
@@ -76,6 +78,9 @@ public class ModuleBatchProcessor<T> extends DynamicCommand {
7678
@Parameter(type = ItemIO.OUTPUT)
7779
private Table outputTable;
7880

81+
@Parameter
82+
private TaskService taskService;
83+
7984
// -- Initializer --
8085

8186
protected void initInputChoice() {
@@ -114,13 +119,27 @@ public void run() {
114119
scriptModule.resolveOutput(outputKey);
115120
}
116121

122+
String taskName = "Batch:";
123+
if (scriptModule.getInfo()!=null) {
124+
if (scriptModule.getInfo().getName()!=null)
125+
taskName = scriptModule.getInfo().getName();
126+
}
127+
Task batchTask = taskService.createTask(taskName);
128+
batchTask.setProgressMaximum(inputFileList.length);
129+
batchTask.setCancelCallBack(() -> batchTask.setStatusMessage("Cancelling batch task..."));
117130
for (File file : inputFileList) {
118-
if(!processFile(scriptModule, inputModuleItem, file)) {
131+
batchTask.setStatusMessage("process "+file.getName());
132+
if (!(processFile(scriptModule, inputModuleItem, file))) {
119133
log.warn("Terminating batch process.");
120134
break; // end for loop
121135
}
136+
if (batchTask.isCanceled()) {
137+
log.warn("Terminating batch process.");
138+
break; // end for loop
139+
}
140+
batchTask.setProgressValue(batchTask.getProgressValue() + 1);
122141
}
123-
142+
batchTask.finish();
124143
// case File
125144
// feed files into input
126145
// case Image (not needed if conversion works

0 commit comments

Comments
 (0)