-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v4.2.6 RC
- Loading branch information
Showing
102 changed files
with
3,728 additions
and
4,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...t/src/main/kotlin/org/dreamexposure/discal/client/business/cronjob/AnnouncementCronJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.dreamexposure.discal.client.business.cronjob | ||
|
||
import discord4j.core.GatewayDiscordClient | ||
import kotlinx.coroutines.reactor.awaitSingle | ||
import kotlinx.coroutines.reactor.mono | ||
import org.dreamexposure.discal.core.business.AnnouncementService | ||
import org.dreamexposure.discal.core.business.MetricService | ||
import org.dreamexposure.discal.core.config.Config | ||
import org.dreamexposure.discal.core.extensions.asMinutes | ||
import org.dreamexposure.discal.core.logger.LOGGER | ||
import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT | ||
import org.springframework.boot.ApplicationArguments | ||
import org.springframework.boot.ApplicationRunner | ||
import org.springframework.stereotype.Component | ||
import org.springframework.util.StopWatch | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.Mono | ||
|
||
@Component | ||
class AnnouncementCronJob( | ||
private val discordClient: GatewayDiscordClient, | ||
private val announcementService: AnnouncementService, | ||
private val metricService: MetricService, | ||
) : ApplicationRunner { | ||
private val interval = Config.TIMING_ANNOUNCEMENT_TASK_RUN_INTERVAL_MINUTES.getLong().asMinutes() | ||
private val maxDifference = interval | ||
|
||
override fun run(args: ApplicationArguments?) { | ||
Flux.interval(interval) | ||
.onBackpressureDrop() | ||
.flatMap { doAction() } | ||
.doOnError { LOGGER.error(DEFAULT, "!-Announcement run error-! Failed to process announcements for all guilds", it) } | ||
.onErrorResume { Mono.empty() } | ||
.subscribe() | ||
} | ||
|
||
private fun doAction() = mono { | ||
val taskTimer = StopWatch() | ||
taskTimer.start() | ||
|
||
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) | ||
} | ||
} | ||
taskTimer.stop() | ||
metricService.recordAnnouncementTaskDuration("cronjob", taskTimer.totalTimeMillis) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ain/kotlin/org/dreamexposure/discal/client/business/cronjob/StaticMessageUpdateCronJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.dreamexposure.discal.client.business.cronjob | ||
|
||
import kotlinx.coroutines.reactor.mono | ||
import org.dreamexposure.discal.Application.Companion.getShardCount | ||
import org.dreamexposure.discal.Application.Companion.getShardIndex | ||
import org.dreamexposure.discal.core.business.MetricService | ||
import org.dreamexposure.discal.core.business.StaticMessageService | ||
import org.dreamexposure.discal.core.config.Config | ||
import org.dreamexposure.discal.core.extensions.asMinutes | ||
import org.dreamexposure.discal.core.logger.LOGGER | ||
import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT | ||
import org.springframework.boot.ApplicationArguments | ||
import org.springframework.boot.ApplicationRunner | ||
import org.springframework.stereotype.Component | ||
import org.springframework.util.StopWatch | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.Mono | ||
import java.time.Duration | ||
import java.time.Instant | ||
|
||
@Component | ||
class StaticMessageUpdateCronJob( | ||
private val staticMessageService: StaticMessageService, | ||
private val metricService: MetricService, | ||
):ApplicationRunner { | ||
override fun run(args: ApplicationArguments?) { | ||
Flux.interval(Config.TIMING_STATIC_MESSAGE_UPDATE_TASK_RUN_INTERVAL_MINUTES.getLong().asMinutes()) | ||
.onBackpressureDrop() | ||
.flatMap { doUpdate() } | ||
.onErrorResume { Mono.empty() } | ||
.subscribe() | ||
} | ||
|
||
private fun doUpdate() = mono { | ||
val taskTimer = StopWatch() | ||
taskTimer.start() | ||
|
||
try { | ||
val messages = staticMessageService.getStaticMessagesForShard(getShardIndex(), getShardCount()) | ||
//We have no interest in updating the message so close to its last update | ||
.filter { Duration.between(Instant.now(), it.lastUpdate).abs().toMinutes() >= 30 } | ||
// Only update messages in range | ||
.filter { Duration.between(Instant.now(), it.scheduledUpdate).toMinutes() <= 60 } | ||
|
||
LOGGER.debug("StaticMessageUpdateCronJob | Found ${messages.size} messages to update for shard ${getShardIndex()}") | ||
|
||
messages.forEach { | ||
try { | ||
staticMessageService.updateStaticMessage(it.guildId, it.messageId) | ||
} catch (ex: Exception) { | ||
LOGGER.error("Failed to update static message | guildId:${it.guildId} | messageId:${it.messageId}", ex) | ||
} | ||
} | ||
} catch (ex: Exception) { | ||
LOGGER.error(DEFAULT, "StaticMessageUpdateCronJob failure", ex) | ||
} finally { | ||
taskTimer.stop() | ||
metricService.recordStaticMessageTaskDuration("cronjob", taskTimer.totalTimeMillis) | ||
} | ||
} | ||
} |
Oops, something went wrong.