Fix/missed automated task execution failure crashes server on startup (#1019)

* Catch automated backup task errors

* Catch automated udpate task errors

* Catch automated webui update task errors
This commit is contained in:
schroda
2024-09-01 00:54:51 +02:00
committed by GitHub
parent 9a1e4df408
commit 5dced82e5a
3 changed files with 40 additions and 26 deletions

View File

@@ -84,9 +84,13 @@ object ProtoBackupExport : ProtoBackupBase() {
} }
val task = { val task = {
cleanupAutomatedBackups() try {
createAutomatedBackup() cleanupAutomatedBackups()
preferences.edit().putLong(LAST_AUTOMATED_BACKUP_KEY, System.currentTimeMillis()).apply() createAutomatedBackup()
preferences.edit().putLong(LAST_AUTOMATED_BACKUP_KEY, System.currentTimeMillis()).apply()
} catch (e: Exception) {
logger.error(e) { "scheduleAutomatedBackupTask: failed due to" }
}
} }
val (hour, minute) = serverConfig.backupTime.value.split(":").map { it.toInt() } val (hour, minute) = serverConfig.backupTime.value.split(":").map { it.toInt() }

View File

@@ -110,20 +110,24 @@ class Updater : IUpdater {
} }
private fun autoUpdateTask() { private fun autoUpdateTask() {
val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, 0) try {
preferences.edit().putLong(lastAutomatedUpdateKey, System.currentTimeMillis()).apply() val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, 0)
preferences.edit().putLong(lastAutomatedUpdateKey, System.currentTimeMillis()).apply()
if (getStatus().running) { if (getStatus().running) {
logger.debug { "Global update is already in progress" } logger.debug { "Global update is already in progress" }
return return
} }
logger.info { logger.info {
"Trigger global update (interval= ${serverConfig.globalUpdateInterval.value}h, lastAutomatedUpdate= ${Date( "Trigger global update (interval= ${serverConfig.globalUpdateInterval.value}h, lastAutomatedUpdate= ${Date(
lastAutomatedUpdate, lastAutomatedUpdate,
)})" )})"
}
addCategoriesToUpdateQueue(Category.getCategoryList(), clear = true, forceAll = false)
} catch (e: Exception) {
logger.error(e) { "autoUpdateTask: failed due to" }
} }
addCategoriesToUpdateQueue(Category.getCategoryList(), clear = true, forceAll = false)
} }
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)

View File

@@ -249,20 +249,26 @@ object WebInterfaceManager {
val lastAutomatedUpdate = preferences.getLong(LAST_WEBUI_UPDATE_CHECK_KEY, System.currentTimeMillis()) val lastAutomatedUpdate = preferences.getLong(LAST_WEBUI_UPDATE_CHECK_KEY, System.currentTimeMillis())
val task = { val task = {
logger.debug { val log =
"Checking for webUI update (" + KotlinLogging.logger(
"flavor= ${WebUIFlavor.current.uiName}, " + "${logger.name}::scheduleWebUIUpdateCheck(" +
"channel= ${serverConfig.webUIChannel.value}, " + "flavor= ${WebUIFlavor.current.uiName}, " +
"interval= ${serverConfig.webUIUpdateCheckInterval.value}h, " + "channel= ${serverConfig.webUIChannel.value}, " +
"lastAutomatedUpdate= ${ "interval= ${serverConfig.webUIUpdateCheckInterval.value}h, " +
Date( "lastAutomatedUpdate= ${
lastAutomatedUpdate, Date(
) lastAutomatedUpdate,
})" )
} })",
)
log.debug { "called" }
runBlocking { runBlocking {
checkForUpdate(WebUIFlavor.current) try {
checkForUpdate(WebUIFlavor.current)
} catch (e: Exception) {
log.error(e) { "failed due to" }
}
} }
} }