-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from iExecBlockchainComputing/reopen
Reopening detector
- Loading branch information
Showing
3 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/com/iexec/core/detector/task/ReopenedTaskDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.iexec.core.detector.task; | ||
|
||
import com.iexec.common.chain.ChainTask; | ||
import com.iexec.common.chain.ChainTaskStatus; | ||
import com.iexec.core.chain.IexecHubService; | ||
import com.iexec.core.detector.Detector; | ||
import com.iexec.core.task.Task; | ||
import com.iexec.core.task.TaskExecutorEngine; | ||
import com.iexec.core.task.TaskService; | ||
import com.iexec.core.task.TaskStatus; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Service | ||
public class ReopenedTaskDetector implements Detector { | ||
|
||
private TaskService taskService; | ||
private TaskExecutorEngine taskExecutorEngine; | ||
private IexecHubService iexecHubService; | ||
|
||
public ReopenedTaskDetector(TaskService taskService, | ||
TaskExecutorEngine taskExecutorEngine, | ||
IexecHubService iexecHubService) { | ||
this.taskService = taskService; | ||
this.taskExecutorEngine = taskExecutorEngine; | ||
this.iexecHubService = iexecHubService; | ||
} | ||
|
||
/** | ||
* Detector to detect tasks that are reopening but are not reopened yet. | ||
*/ | ||
@Scheduled(fixedRateString = "${detector.task.finalized.unnotified.period}") | ||
@Override | ||
public void detect() { | ||
log.info("Trying to detect reopened tasks"); | ||
for (Task task : taskService.findByCurrentStatus(TaskStatus.REOPENING)) { | ||
Optional<ChainTask> oChainTask = iexecHubService.getChainTask(task.getChainTaskId()); | ||
if (!oChainTask.isPresent()){ | ||
continue; | ||
} | ||
|
||
ChainTask chainTask = oChainTask.get(); | ||
if (chainTask.getStatus().equals(ChainTaskStatus.ACTIVE)) { | ||
taskExecutorEngine.updateTask(task.getChainTaskId()); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters