Skip to content

Commit

Permalink
Add better error catching for announcement cron job
Browse files Browse the repository at this point in the history
This should keep the announcement job from crapping out when a major error occurs
  • Loading branch information
NovaFox161 committed Jun 23, 2024
1 parent d627a21 commit 2f6c1c7
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,23 @@ class AnnouncementCronJob(
}

private fun doAction() = mono {
val taskTimer = StopWatch()
taskTimer.start()
try {
val taskTimer = StopWatch()
taskTimer.start()

val guilds = discordClient.guilds.collectList().awaitSingle()
val guilds = discordClient.guilds.collectList().awaitSingle()

guilds.forEach { guild ->
try {
announcementService.processAnnouncementsForGuild(guild.id, maxDifference)
} catch (ex: Exception) {
LOGGER.error("Failed to process announcements for guild | guildId:${guild.id.asLong()}", ex)
guilds.forEach { guild ->
try {
announcementService.processAnnouncementsForGuild(guild.id, maxDifference)
} catch (ex: Exception) {
LOGGER.error("Failed to process announcements for guild | guildId:${guild.id.asLong()}", ex)
}
}
taskTimer.stop()
metricService.recordAnnouncementTaskDuration("cronjob", taskTimer.totalTimeMillis)
} catch (ex: Exception) {
LOGGER.error(DEFAULT, "Announcement task failed for all guilds", ex)
}
taskTimer.stop()
metricService.recordAnnouncementTaskDuration("cronjob", taskTimer.totalTimeMillis)
}
}

0 comments on commit 2f6c1c7

Please sign in to comment.