diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a4942bb..094c2af9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575) - Refactor unnotified detectors to avoid code duplication. (#580) - Use `==` or `!=` operators to test the equality of enums. (#584) +- Rearrange checks order to avoid call to database. (#585) ### Dependency Upgrades - Upgrade to `iexec-common` 8.1.0-NEXT-SNAPSHOT. (#571 #575 #586) - Add new `iexec-commons-poco` 2.0.0 dependency. (#571 #574 #586) diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index bf818527a..940894284 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -330,7 +330,12 @@ void running2ConsensusReached(Task task) { void running2Finalized2Completed(Task task) { boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING; final String chainTaskId = task.getChainTaskId(); - final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); + + if (!task.isTeeTask()) { + log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible" + + " [chainTaskId:{}]", chainTaskId); + return; + } if (!isTaskInRunningStatus) { log.error("Can't transition task to `Finalized` or `Completed` when task is not `Running` " + @@ -338,17 +343,13 @@ void running2Finalized2Completed(Task task) { return; } + final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); if (oReplicatesList.isEmpty()) { log.error("Can't transition task to `Finalized` or `Completed` when no replicatesList exists" + " [chainTaskId:{}]", chainTaskId); return; } - if (!task.isTeeTask()) { - log.debug("Task not running in a TEE, flow running2Finalized2Completed is not possible" - + " [chainTaskId:{}]", chainTaskId); - return; - } final ReplicatesList replicates = oReplicatesList.get(); final int nbReplicatesWithContributeAndFinalizeStatus = replicates.getNbReplicatesWithCurrentStatus(ReplicateStatus.CONTRIBUTE_AND_FINALIZE_DONE); diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index 8aef17a45..eb82b0c74 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -688,6 +688,7 @@ void shouldUpdateFromInitializedOrRunning2ContributionTimeout() { void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { Task task = getStubTask(maxExecutionTime); task.changeStatus(INITIALIZED); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); taskUpdateManager.running2Finalized2Completed(task); assertThat(task.getCurrentStatus()).isEqualTo(INITIALIZED); @@ -697,6 +698,7 @@ void shouldNotUpdateRunning2Finalized2CompletedWhenTaskNotRunning() { void shouldNotUpdateRunning2Finalized2CompletedWhenNoReplicates() { Task task = getStubTask(maxExecutionTime); task.changeStatus(RUNNING); + task.setTag(TeeUtils.TEE_SCONE_ONLY_TAG); when(replicatesService.getReplicatesList(CHAIN_TASK_ID)).thenReturn(Optional.empty());