Add global role synchronization for Discord with configurable interval
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / compose (push) Has been cancelled

This commit introduces a new feature for global role synchronization in Discord, allowing for periodic reconciliation of managed roles. A new environment variable, `DISCORD_GLOBAL_SYNC_INTERVAL`, has been added to configure the synchronization interval, defaulting to 5 minutes. The `RoleWorker` has been updated to schedule global sync jobs, ensuring that missing managed roles are restored and extra assignments are removed without affecting unrelated server roles. Database schema changes support the new synchronization logic, and tests have been added to validate the functionality of the global reconciliation process.
This commit is contained in:
2026-07-19 12:04:33 +03:00
parent e5646ba33d
commit 6b189bfce4
14 changed files with 568 additions and 42 deletions

View File

@@ -59,9 +59,10 @@ func main() {
discordGuildID := os.Getenv("DISCORD_GUILD_ID")
if discordGuildID != "" {
roleWorker, roleErr := discordadapter.NewRoleWorker(store, discordadapter.RoleSyncConfig{
BotToken: discordBotToken,
GuildID: discordGuildID,
Locale: env("DISCORD_ANNOUNCEMENT_LOCALE", "ru"),
BotToken: discordBotToken,
GuildID: discordGuildID,
Locale: env("DISCORD_ANNOUNCEMENT_LOCALE", "ru"),
GlobalSyncInterval: durationEnv("DISCORD_GLOBAL_SYNC_INTERVAL", 5*time.Minute),
})
if roleErr != nil {
slog.Error("Discord role sync configuration failed", "error", roleErr)