feat: add ding for ordered go routine shutdown

This commit is contained in:
Stavros
2026-05-24 18:44:31 +03:00
parent 2737a25227
commit 33ee4f8b15
11 changed files with 107 additions and 100 deletions
+5 -4
View File
@@ -9,6 +9,7 @@ import (
"sync"
"time"
"github.com/steveiliop56/ding"
"github.com/tinyauthapp/tinyauth/internal/model"
"github.com/tinyauthapp/tinyauth/internal/repository"
"github.com/tinyauthapp/tinyauth/internal/utils"
@@ -96,7 +97,7 @@ func NewAuthService(
config model.Config,
runtime model.RuntimeConfig,
ctx context.Context,
wg *sync.WaitGroup,
dg *ding.Ding,
ldap *LdapService,
queries repository.Store,
oauthBroker *OAuthBrokerService,
@@ -116,7 +117,7 @@ func NewAuthService(
tailscale: tailscale,
}
wg.Go(service.CleanupOAuthSessionsRoutine)
dg.Go(service.cleanupOAuthSessions, ding.RingMinor)
return service
}
@@ -584,7 +585,7 @@ func (auth *AuthService) EndOAuthSession(sessionId string) {
auth.oauthMutex.Unlock()
}
func (auth *AuthService) CleanupOAuthSessionsRoutine() {
func (auth *AuthService) cleanupOAuthSessions(ctx context.Context) {
auth.log.App.Debug().Msg("Starting OAuth session cleanup routine")
ticker := time.NewTicker(30 * time.Minute)
@@ -607,7 +608,7 @@ func (auth *AuthService) CleanupOAuthSessionsRoutine() {
auth.oauthMutex.Unlock()
auth.log.App.Debug().Msg("OAuth session cleanup completed")
case <-auth.context.Done():
case <-ctx.Done():
auth.log.App.Debug().Msg("Stopping OAuth session cleanup routine")
return
}