1
0
Fork 1
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-01-19 02:48:37 +00:00

Add start of reloading client settings

Added new client settings paramter 'settingsReloadDelayInMinutes'
to handle how often the client settings are updated.
Added scheduler to call a new 'reloadClientSettings' method when
it's time to reload client settings.
This commit is contained in:
radonbark 2020-07-12 14:48:06 -04:00
parent c0fff9e09f
commit e2897ec595
2 changed files with 32 additions and 2 deletions

View file

@ -51,7 +51,7 @@ object Shutdown : State()
// server is in the process of shutting down
data class GracefulShutdown(val lastRunning: Running, val counts: Int = 0, val nextState: State = Uninitialized, val action: () -> Unit = {}) : State()
// server is currently running
data class Running(val server: Http4kServer, val settings: ServerSettings) : State()
data class Running(val server: Http4kServer, val settings: ServerSettings, val minutesToSettingsReload: Int) : State()
class MangaDexClient(private val clientSettings: ClientSettings) {
// this must remain singlethreaded because of how the state mechanism works
@ -195,6 +195,26 @@ class MangaDexClient(private val clientSettings: ClientSettings) {
LOGGER.warn(e) { "Graceful shutdown checker failed" }
}
}, 45, 45, TimeUnit.SECONDS)
// Check every minute to see if we need to reload the client settings
executorService.scheduleWithFixedDelay({
try {
val state = this.state
if (state is Running) {
val minutesToNextReload = state.minutesToSettingsReload
if (minutesToNextReload <= 0) {
reloadClientSettings()
this.state = state.copy(minutesToSettingsReload = clientSettings.settingsReloadDelayInMinutes)
}
else {
this.state = state.copy(minutesToSettingsReload = minutesToNextReload - 1)
}
LOGGER.info { "Time to next client settings reload: " + minutesToNextReload }
}
} catch (e: Exception) {
LOGGER.warn(e) { "Client settings reloader failed" }
}
}, 1, 1, TimeUnit.MINUTES)
}
private fun pingControl() {
@ -235,7 +255,7 @@ class MangaDexClient(private val clientSettings: ClientSettings) {
}
}
state = Running(server, serverSettings)
state = Running(server, serverSettings, clientSettings.settingsReloadDelayInMinutes)
LOGGER.info { "Internal HTTP server was successfully started" }
}
@ -296,6 +316,15 @@ class MangaDexClient(private val clientSettings: ClientSettings) {
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
}
/**
* Reloads the client configuration and restarts the
* Web UI and/or the server if needed
*/
private fun reloadClientSettings() {
val state = this.state
LOGGER.info { "Reloading client settings" }
}
companion object {
private val LOGGER = LoggerFactory.getLogger(MangaDexClient::class.java)
private val JACKSON: ObjectMapper = jacksonObjectMapper()

View file

@ -34,6 +34,7 @@ data class ClientSettings(
@field:Secret val clientSecret: String = "PASTE-YOUR-SECRET-HERE",
val threads: Int = 4,
val gracefulShutdownWaitSeconds: Int = 60,
val settingsReloadDelayInMinutes: Int = 60, // Once per hour
val webSettings: WebSettings? = null,
val devSettings: DevSettings? = null
)