From 0e6af9e7d3ed2704100410a978b2d95f72169d88 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Sun, 28 Jun 2020 12:36:30 -0500 Subject: [PATCH] Add sanity guard --- src/main/kotlin/mdnet/base/MangaDexClient.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/mdnet/base/MangaDexClient.kt b/src/main/kotlin/mdnet/base/MangaDexClient.kt index aac30e9..8497370 100644 --- a/src/main/kotlin/mdnet/base/MangaDexClient.kt +++ b/src/main/kotlin/mdnet/base/MangaDexClient.kt @@ -101,14 +101,16 @@ class MangaDexClient(private val clientSettings: ClientSettings) { executorService.scheduleAtFixedRate({ try { - statistics.updateAndGet { - it.copy(bytesOnDisk = cache.size()) - } - statsMap[Instant.now()] = statistics.get() - val editor = cache.edit("statistics") - if (editor != null) { - JACKSON.writeValue(editor.newOutputStream(0), statistics.get()) - editor.commit() + if (state is Running || state is GracefulShutdown || state is Uninitialized) { + statistics.updateAndGet { + it.copy(bytesOnDisk = cache.size()) + } + statsMap[Instant.now()] = statistics.get() + val editor = cache.edit("statistics") + if (editor != null) { + JACKSON.writeValue(editor.newOutputStream(0), statistics.get()) + editor.commit() + } } } catch (e: Exception) { LOGGER.warn("Statistics update failed", e)