notifications

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartWithFallback

func StartWithFallback(ctx context.Context, connStr string, service *Service)

StartWithFallback starts the listener with polling fallback. This is useful when the database doesn't support LISTEN (e.g., connection poolers). If DATABASE_DIRECT_URL is set, tests the connection first and uses it for real-time LISTEN/NOTIFY. Falls back to polling if the direct connection fails or is unavailable.

Types

type DeliveryChannel

type DeliveryChannel interface {
	Name() string
	Deliver(ctx context.Context, n *db.Notification) error
}

DeliveryChannel defines the interface for notification delivery

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener listens for PostgreSQL notifications and triggers delivery

func NewListener

func NewListener(connStr string, service *Service) *Listener

NewListener creates a new notification listener. Returns nil if service is nil to prevent nil pointer dereferences.

func (*Listener) Start

func (l *Listener) Start(ctx context.Context)

Start begins listening for notifications It uses PostgreSQL LISTEN/NOTIFY for real-time delivery Falls back to polling if the connection fails

type NotificationDB

type NotificationDB interface {
	GetPendingSlackNotifications(ctx context.Context, limit int) ([]*db.Notification, error)
	MarkNotificationDelivered(ctx context.Context, notificationID, channel string) error
	GetSlackConnectionsForOrg(ctx context.Context, organisationID string) ([]*db.SlackConnection, error)
	GetEnabledUserLinksForConnection(ctx context.Context, connectionID string) ([]*db.SlackUserLink, error)
}

NotificationDB defines the database operations needed by the service

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles notification delivery to various channels. Note: Notifications are created by PostgreSQL triggers, not Go code.

func NewService

func NewService(database NotificationDB) *Service

NewService creates a notification service

func (*Service) AddChannel

func (s *Service) AddChannel(ch DeliveryChannel)

AddChannel adds a delivery channel to the service

func (*Service) ProcessPendingNotifications

func (s *Service) ProcessPendingNotifications(ctx context.Context, limit int) error

ProcessPendingNotifications delivers pending notifications to all channels

type SlackChannel

type SlackChannel struct {
	// contains filtered or unexported fields
}

SlackChannel implements the DeliveryChannel interface for Slack

func NewSlackChannel

func NewSlackChannel(database SlackDB) (*SlackChannel, error)

NewSlackChannel creates a new Slack delivery channel

func (*SlackChannel) Deliver

func (c *SlackChannel) Deliver(ctx context.Context, n *db.Notification) error

Deliver sends a notification to Slack

func (*SlackChannel) Name

func (c *SlackChannel) Name() string

Name returns the channel name

type SlackDB

type SlackDB interface {
	GetSlackConnectionsForOrg(ctx context.Context, organisationID string) ([]*db.SlackConnection, error)
	GetEnabledUserLinksForConnection(ctx context.Context, connectionID string) ([]*db.SlackUserLink, error)
	GetSlackToken(ctx context.Context, connectionID string) (string, error)
}

SlackDB defines Slack-specific database operations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL