Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SPV-1357): webhook tests #843

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion engine/notifications/webhook_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type WebhookManager struct {
banMsg chan string // url
notifications *Notifications
logger *zerolog.Logger
endMsg chan bool
}

// NewWebhookManager creates a new WebhookManager. It starts a goroutine which checks for webhook updates.
Expand All @@ -41,6 +42,7 @@ func NewWebhookManager(ctx context.Context, logger *zerolog.Logger, notification
updateMsg: make(chan bool),
banMsg: make(chan string),
logger: logger,
endMsg: make(chan bool),
dorzepowski marked this conversation as resolved.
Show resolved Hide resolved
}

go manager.checkForUpdates()
Expand All @@ -50,7 +52,11 @@ func NewWebhookManager(ctx context.Context, logger *zerolog.Logger, notification

// Stop stops the WebhookManager.
func (w *WebhookManager) Stop() {
w.ticker.Stop()
w.cancelAllFunc()

<-w.endMsg
w.logger.Info().Msg("WebhookManager stopped")
}

// Subscribe subscribes to a webhook. It adds the webhook to the database and starts a notifier for it.
Expand Down Expand Up @@ -100,7 +106,7 @@ func (w *WebhookManager) GetAll(ctx context.Context) ([]ModelWebhook, error) {

func (w *WebhookManager) checkForUpdates() {
defer func() {
w.logger.Info().Msg("WebhookManager stopped")
w.endMsg <- true
dorzepowski marked this conversation as resolved.
Show resolved Hide resolved
if err := recover(); err != nil {
w.logger.Warn().Msgf("WebhookManager failed: %v", err)
}
Expand Down
Loading