diff --git a/src/main/java/ru/r2cloud/tle/Housekeeping.java b/src/main/java/ru/r2cloud/tle/Housekeeping.java index e02762f5..6df10bd1 100644 --- a/src/main/java/ru/r2cloud/tle/Housekeeping.java +++ b/src/main/java/ru/r2cloud/tle/Housekeeping.java @@ -1,10 +1,14 @@ package ru.r2cloud.tle; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import ru.r2cloud.cloud.LeoSatDataClient; import ru.r2cloud.cloud.NotModifiedException; import ru.r2cloud.cloud.SatnogsClient; @@ -20,6 +24,8 @@ public class Housekeeping { + private static final Logger LOG = LoggerFactory.getLogger(Housekeeping.class); + private final ThreadPoolFactory threadFactory; private final SatelliteDao dao; private final Configuration config; @@ -136,13 +142,15 @@ private boolean reloadSatellites() { private void reloadTle() { long periodMillis = config.getLong("housekeeping.tle.periodMillis"); - // do not store on disk ever growing tle list - // store only supported satellites - Map updated = new HashMap<>(); boolean reloadTle = (System.currentTimeMillis() - tleDao.getLastUpdateTime() > periodMillis); if (reloadTle) { tleDao.putAll(celestrak.downloadTle()); + } else { + LOG.info("Skip TLE update. Last update was {}. Next update: {}", new Date(tleDao.getLastUpdateTime()), new Date(tleDao.getLastUpdateTime() + periodMillis)); } + // do not store on disk ever growing tle list + // store only supported satellites + Map updated = new HashMap<>(); for (Satellite cur : dao.findAll()) { Tle curTle; if (cur.getTle() != null) { diff --git a/src/main/java/ru/r2cloud/tle/TleDao.java b/src/main/java/ru/r2cloud/tle/TleDao.java index d603598c..a0865bc2 100644 --- a/src/main/java/ru/r2cloud/tle/TleDao.java +++ b/src/main/java/ru/r2cloud/tle/TleDao.java @@ -15,6 +15,7 @@ import com.eclipsesource.json.Json; import com.eclipsesource.json.JsonArray; +import com.eclipsesource.json.WriterConfig; import ru.r2cloud.model.Tle; import ru.r2cloud.util.Configuration; @@ -92,7 +93,7 @@ private static void saveTle(Path file, Map tle) { // ensure temp and output are on the same filestore Path tempOutput = file.getParent().resolve("tle.json.tmp"); try (BufferedWriter w = Files.newBufferedWriter(tempOutput)) { - output.writeTo(w); + output.writeTo(w, WriterConfig.PRETTY_PRINT); } catch (IOException e) { Util.logIOException(LOG, "unable to save tle: " + file.toAbsolutePath(), e); return;