Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Aug 2, 2024
1 parent b756e90 commit 2d09f22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/main/java/ru/r2cloud/tle/Housekeeping.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Tle> 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<String, Tle> updated = new HashMap<>();
for (Satellite cur : dao.findAll()) {
Tle curTle;
if (cur.getTle() != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ru/r2cloud/tle/TleDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,7 +93,7 @@ private static void saveTle(Path file, Map<String, Tle> 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;
Expand Down

0 comments on commit 2d09f22

Please sign in to comment.