From 0fd5a1200c0c11850514a142033c08b90ac8d4d1 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Mon, 17 Jun 2024 14:24:42 +0200 Subject: [PATCH 1/8] Stops extracting when the job is cancelled Fixes: SIRI-972 --- .../biz/storage/layer3/ExtractArchiveJob.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java b/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java index f9009c7da..c1cb161e2 100644 --- a/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java +++ b/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java @@ -137,14 +137,12 @@ protected void execute(ProcessContext process) throws Exception { .withContext("size", NLS.formatSize(sourceFile.size()))); try (FileHandle archive = sourceFile.download()) { - extractor.extractAll(sourceFile.name(), - archive.getFile(), - null, - file -> handleExtractedFile(file, - process, - overrideMode, - targetDirectory, - flattenDirs)); + extractor.extractAll(sourceFile.name(), archive.getFile(), null, file -> { + if (!process.isActive()) { + return; + } + handleExtractedFile(file, process, overrideMode, targetDirectory, flattenDirs); + }); process.forceUpdateState(NLS.get("ExtractArchiveJob.completed")); } catch (Exception exception) { process.log(ProcessLog.error().withMessage(exception.getMessage())); From 14dee27011dda8adb0dce8e35514620d825399da Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Mon, 17 Jun 2024 14:25:14 +0200 Subject: [PATCH 2/8] Extracts duplicate strings into constant values Fixes: SIRI-972 --- .../sirius/biz/storage/layer3/ExtractArchiveJob.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java b/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java index c1cb161e2..8a4359a93 100644 --- a/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java +++ b/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java @@ -79,6 +79,8 @@ public class ExtractArchiveJob extends SimpleBatchProcessJobFactory { private static final String FILE_SKIPPED_COUNTER = "ExtractArchiveJob.fileSkipped"; private static final String FILE_EMPTY_COUNTER = "ExtractArchiveJob.fileEmpty"; + private static final String ARCHIVE_JOB_EMPTY_FILE = "ExtractArchiveJob.emptyFile"; + private static final String FILENAME = "filename"; /** * Creates the job factory so that it can be invoked by the framework. @@ -165,7 +167,7 @@ private void handleExtractedFile(ExtractedFile extractedFile, if (extractedFile == null) { // if this happens we don't know the file name of this entry, we just log with an empty name - process.log(ProcessLog.warn().withNLSKey("ExtractArchiveJob.emptyFile").withContext("filename", "")); + process.log(ProcessLog.warn().withNLSKey(ARCHIVE_JOB_EMPTY_FILE).withContext(FILENAME, "")); process.addTiming(FILE_EMPTY_COUNTER, watch.elapsedMillis()); return; } @@ -176,8 +178,8 @@ private void handleExtractedFile(ExtractedFile extractedFile, if (extractedFile.size() == 0) { process.log(ProcessLog.warn() - .withNLSKey("ExtractArchiveJob.emptyFile") - .withContext("filename", extractedFile.getFilePath())); + .withNLSKey(ARCHIVE_JOB_EMPTY_FILE) + .withContext(FILENAME, extractedFile.getFilePath())); process.addTiming(FILE_EMPTY_COUNTER, watch.elapsedMillis()); return; } @@ -186,8 +188,8 @@ private void handleExtractedFile(ExtractedFile extractedFile, VirtualFile targetFile = fetchTargetFile(targetDirectory, targetPath); if (targetFile == null) { process.log(ProcessLog.warn() - .withNLSKey("ExtractArchiveJob.emptyFile") - .withContext("filename", extractedFile.getFilePath())); + .withNLSKey(ARCHIVE_JOB_EMPTY_FILE) + .withContext(FILENAME, extractedFile.getFilePath())); process.addTiming(FILE_SKIPPED_COUNTER, watch.elapsedMillis()); return; } From dda3e98de2d5cfc6ff78f89638d097364488a80a Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Mon, 17 Jun 2024 17:12:27 +0200 Subject: [PATCH 3/8] Implements check if the user cancelled the job If it was cancelled we set the state to "cancelled" instead of "terminated" Fixes: SIRI-972 --- src/main/java/sirius/biz/process/Processes.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/process/Processes.java b/src/main/java/sirius/biz/process/Processes.java index fd0afa932..a61c01dfc 100644 --- a/src/main/java/sirius/biz/process/Processes.java +++ b/src/main/java/sirius/biz/process/Processes.java @@ -599,7 +599,12 @@ protected boolean markCompleted(String processId, return modify(processId, process -> process.getState() != ProcessState.TERMINATED, process -> { if (process.getState() != ProcessState.STANDBY) { process.setErrorneous(process.isErrorneous() || !TaskContext.get().isActive()); - process.setState(ProcessState.TERMINATED); + //Do not alter the job state if the job was previously cancelled by the user + if (process.getState() != ProcessState.CANCELED) { + process.setState(ProcessState.TERMINATED); + } else { + process.setState(ProcessState.CANCELED); + } process.setCompleted(LocalDateTime.now()); process.setComputationTime(process.getComputationTime() + computationTimeInSeconds); process.setExpires(process.getPersistencePeriod().plus(LocalDate.now())); From ba37026add154d693154aa8bf5385e8d185787c4 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 18 Jun 2024 09:16:56 +0200 Subject: [PATCH 4/8] Changes check for state to check if job has been cancelled Fixes: SIRI-972 --- src/main/java/sirius/biz/process/Processes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/process/Processes.java b/src/main/java/sirius/biz/process/Processes.java index a61c01dfc..6e0a68ea8 100644 --- a/src/main/java/sirius/biz/process/Processes.java +++ b/src/main/java/sirius/biz/process/Processes.java @@ -600,7 +600,7 @@ protected boolean markCompleted(String processId, if (process.getState() != ProcessState.STANDBY) { process.setErrorneous(process.isErrorneous() || !TaskContext.get().isActive()); //Do not alter the job state if the job was previously cancelled by the user - if (process.getState() != ProcessState.CANCELED) { + if (process.getCanceled()==null) { process.setState(ProcessState.TERMINATED); } else { process.setState(ProcessState.CANCELED); From 53ad7441b5362b0f3799e8761ba42198014cc1be Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 18 Jun 2024 09:17:19 +0200 Subject: [PATCH 5/8] Moves setCompleted to where it should be Fixes: SIRI-972 --- src/main/java/sirius/biz/process/Processes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/process/Processes.java b/src/main/java/sirius/biz/process/Processes.java index 6e0a68ea8..4f5f4d569 100644 --- a/src/main/java/sirius/biz/process/Processes.java +++ b/src/main/java/sirius/biz/process/Processes.java @@ -602,10 +602,10 @@ protected boolean markCompleted(String processId, //Do not alter the job state if the job was previously cancelled by the user if (process.getCanceled()==null) { process.setState(ProcessState.TERMINATED); + process.setCompleted(LocalDateTime.now()); } else { process.setState(ProcessState.CANCELED); } - process.setCompleted(LocalDateTime.now()); process.setComputationTime(process.getComputationTime() + computationTimeInSeconds); process.setExpires(process.getPersistencePeriod().plus(LocalDate.now())); } From 08980e991259de0ed4be6f547d358a789babd02d Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 18 Jun 2024 09:22:59 +0200 Subject: [PATCH 6/8] Changes extraction completion to only show if job wasn't cancelled Fixes: SIRI-972 --- .../java/sirius/biz/storage/layer3/ExtractArchiveJob.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java b/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java index 8a4359a93..f12f393f5 100644 --- a/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java +++ b/src/main/java/sirius/biz/storage/layer3/ExtractArchiveJob.java @@ -145,7 +145,9 @@ protected void execute(ProcessContext process) throws Exception { } handleExtractedFile(file, process, overrideMode, targetDirectory, flattenDirs); }); - process.forceUpdateState(NLS.get("ExtractArchiveJob.completed")); + if(processes.fetchProcessForUser(process.getProcessId()).orElse(null).getCanceled() == null){ + process.forceUpdateState(NLS.get("ExtractArchiveJob.completed")); + } } catch (Exception exception) { process.log(ProcessLog.error().withMessage(exception.getMessage())); } From b005838780445682246952c3eec2af20644464c8 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 18 Jun 2024 10:33:57 +0200 Subject: [PATCH 7/8] Removes else, due to not being needed Fixes: SIRI-972 --- src/main/java/sirius/biz/process/Processes.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/sirius/biz/process/Processes.java b/src/main/java/sirius/biz/process/Processes.java index 4f5f4d569..ab9f1b48f 100644 --- a/src/main/java/sirius/biz/process/Processes.java +++ b/src/main/java/sirius/biz/process/Processes.java @@ -603,8 +603,6 @@ protected boolean markCompleted(String processId, if (process.getCanceled()==null) { process.setState(ProcessState.TERMINATED); process.setCompleted(LocalDateTime.now()); - } else { - process.setState(ProcessState.CANCELED); } process.setComputationTime(process.getComputationTime() + computationTimeInSeconds); process.setExpires(process.getPersistencePeriod().plus(LocalDate.now())); From 7c69c6b5c3e279a96edc3c71376a3a644d958066 Mon Sep 17 00:00:00 2001 From: Mauricio Muler Bodemann Date: Tue, 18 Jun 2024 10:34:39 +0200 Subject: [PATCH 8/8] Changes check back to look for state "CANCELLED" Fixes: SIRI-972 --- src/main/java/sirius/biz/process/Processes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/process/Processes.java b/src/main/java/sirius/biz/process/Processes.java index ab9f1b48f..1b02478e2 100644 --- a/src/main/java/sirius/biz/process/Processes.java +++ b/src/main/java/sirius/biz/process/Processes.java @@ -600,7 +600,7 @@ protected boolean markCompleted(String processId, if (process.getState() != ProcessState.STANDBY) { process.setErrorneous(process.isErrorneous() || !TaskContext.get().isActive()); //Do not alter the job state if the job was previously cancelled by the user - if (process.getCanceled()==null) { + if (process.getState() != ProcessState.CANCELED) { process.setState(ProcessState.TERMINATED); process.setCompleted(LocalDateTime.now()); }