From 49c96fb1cf8b05f4b5b468381ac66a8bb683b0a6 Mon Sep 17 00:00:00 2001 From: Ludovic Claude <ludovic.claude@laposte.net> Date: Wed, 25 Apr 2018 00:47:33 +0200 Subject: [PATCH] Improve startup --- src/main/java/eu/hbp/mip/StartupTasks.java | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/hbp/mip/StartupTasks.java b/src/main/java/eu/hbp/mip/StartupTasks.java index a72e11952..4fc511a7a 100644 --- a/src/main/java/eu/hbp/mip/StartupTasks.java +++ b/src/main/java/eu/hbp/mip/StartupTasks.java @@ -40,17 +40,22 @@ public class StartupTasks implements ApplicationListener<ApplicationReadyEvent> public void onApplicationEvent(ApplicationReadyEvent event) { // Pre-fill the local variable repository with the list of datasets, interpreted here as variables // (a bit like a categorical variable can be split into a set of variables (a.k.a one hot encoding in Data science) ) - try { - for (Dataset dataset: datasetsApi.fetchDatasets()) { - final String code = dataset.dataset().code(); - Variable v = variableRepository.findOne(code); - if (v == null) { - v = new Variable(code); - variableRepository.save(v); + // Try 5 times, to be more robust in the face of cluster failures / slow startup + for (int i = 0; i < 5; i++) { + try { + for (Dataset dataset : datasetsApi.fetchDatasets()) { + final String code = dataset.dataset().code(); + Variable v = variableRepository.findOne(code); + if (v == null) { + v = new Variable(code); + variableRepository.save(v); + } } + LOGGER.info("Datasets fetched from Woken"); + break; + } catch (Exception e) { + LOGGER.error("Cannot initialise the variable repository. Is the connection to Woken working?", e); } - } catch (Exception e) { - LOGGER.error("Cannot initialise the variable repository. Is the connection to Woken working?", e); } /* -- GitLab