Skip to content

Commit

Permalink
Merge pull request #11 from KPMP/KPMP-1516
Browse files Browse the repository at this point in the history
Kpmp 1516
  • Loading branch information
rlreamy authored Dec 19, 2019
2 parents 7e3a0f6 + 3c2e52c commit 4ff49f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/org/kpmp/stateManager/StateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -24,6 +25,9 @@ public class StateController {
private StateService stateService;
private static final Log log = LogFactory.getLog(StateController.class);

@Value("${package.state.longpoll.timeout}")
Long longPollTimeoutMillis;

@Autowired
public StateController(StateService stateService) {
this.stateService = stateService;
Expand Down Expand Up @@ -57,10 +61,8 @@ public StateController(StateService stateService) {

log.info("URI: " + request.getRequestURI() + " | MSG: Long poll for events after " + stateChangeDate);

// Timeout after 1 minute
Long timeOutInMilliSec = 60000L;
String timeOutResp = "{\"timeout\": true}";
DeferredResult<List<State>> deferredResult = new DeferredResult<>(timeOutInMilliSec, timeOutResp);
DeferredResult<List<State>> deferredResult = new DeferredResult<>(longPollTimeoutMillis, timeOutResp);
CompletableFuture.runAsync(() -> {
try {
List<State> result = stateService.findPackagesChangedAfterStateChangeDate(stateChangeDate);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/kpmp/stateManager/StateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -24,6 +26,7 @@ public StateService(CustomStateRepository stateRepository, NotificationHandler n
this.notificationHandler = notificationHandler;
}

@CacheEvict(value = "states", allEntries = true)
public String setState(State state, String origin) {
State savedState = stateRepository.save(state);
notificationHandler.sendNotification(state.getPackageId(), state.getState(), origin, state.getCodicil());
Expand Down Expand Up @@ -55,6 +58,7 @@ public Boolean isPackageFailed(String packageId) {
return failedState != null;
}

@Cacheable(value = "states")
public List<State> getAllCurrentStates() {
List<State> states = new ArrayList<State>();
List<String> packageIds = stateRepository.findAllPackageIds();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ package.state.upload.started=UPLOAD_STARTED
package.state.files.received=FILES_RECEIVED
package.state.upload.failed=UPLOAD_FAILED

package.state.longpoll.timeout=60000
package.state.checker.timeout=1800000
package.state.checker.checkaftermillis=86400000

0 comments on commit 4ff49f3

Please sign in to comment.