Search in sources :

Example 1 with FailedCacheRefreshException

use of org.mskcc.oncotree.utils.FailedCacheRefreshException in project oncotree by cBioPortal.

the class MSKConceptCache method resetCache.

@EventListener(ApplicationReadyEvent.class)
// call every Sunday at 3am
@Scheduled(cron = "0 0 3 * * SUN")
private // the actual returned MSKConcept is not necessary for webapp deployment
void resetCache() throws Exception {
    logger.info("resetCache() -- attempting to refresh Crosswalk MSKConcept cache");
    HashMap<String, MSKConcept> latestOncoTreeCodesToMSKConcepts = new HashMap<String, MSKConcept>();
    ArrayList<Version> oncoTreeVersions = new ArrayList<Version>();
    try {
        oncoTreeVersions = oncoTreePersistentCache.getOncoTreeVersionsFromPersistentCache();
    } catch (RuntimeException e) {
        throw new FailedCacheRefreshException("Failed to refresh MSKConceptCache, unable to load verisons...");
    }
    for (Version version : oncoTreeVersions) {
        ArrayList<OncoTreeNode> oncoTreeNodes = new ArrayList<OncoTreeNode>();
        try {
            oncoTreeNodes = oncoTreePersistentCache.getOncoTreeNodesFromPersistentCache(version);
        } catch (RuntimeException e) {
            throw new FailedCacheRefreshException("Failed to refresh MSKConceptCache : " + e.toString());
        }
        for (OncoTreeNode node : oncoTreeNodes) {
            // skip querying repeated nodes/MSKConcepts
            if (!latestOncoTreeCodesToMSKConcepts.containsKey(node.getCode())) {
                // pull from crosswalk first
                oncoTreePersistentCache.updateMSKConceptInPersistentCache(node.getCode());
                MSKConcept concept = oncoTreePersistentCache.getMSKConceptFromPersistentCache(node.getCode());
                latestOncoTreeCodesToMSKConcepts.put(node.getCode(), concept);
            }
        }
    }
    // save all MSKConcepts at once
    try {
        oncoTreePersistentCache.backupMSKConceptPersistentCache(latestOncoTreeCodesToMSKConcepts);
    } catch (Exception e) {
        logger.error("Unable to backup MSKConcepts in EHCache");
        slackUtil.sendSlackNotification("*OncoTree Error* - MSKConceptCache backup failed." + e.getMessage());
    }
}
Also used : FailedCacheRefreshException(org.mskcc.oncotree.utils.FailedCacheRefreshException) Version(org.mskcc.oncotree.model.Version) OncoTreeNode(org.mskcc.oncotree.topbraid.OncoTreeNode) TopBraidException(org.mskcc.oncotree.topbraid.TopBraidException) FailedCacheRefreshException(org.mskcc.oncotree.utils.FailedCacheRefreshException) Scheduled(org.springframework.scheduling.annotation.Scheduled) EventListener(org.springframework.context.event.EventListener)

Aggregations

Version (org.mskcc.oncotree.model.Version)1 OncoTreeNode (org.mskcc.oncotree.topbraid.OncoTreeNode)1 TopBraidException (org.mskcc.oncotree.topbraid.TopBraidException)1 FailedCacheRefreshException (org.mskcc.oncotree.utils.FailedCacheRefreshException)1 EventListener (org.springframework.context.event.EventListener)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1