notifications

package
v1.21.31 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package notifications provides database notification services that work across different database backends (PostgreSQL and Oracle).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DatabaseType is "postgres" or "oracle"
	DatabaseType string

	// PostgresConnectionString for PostgreSQL LISTEN/NOTIFY
	PostgresConnectionString string

	// For Oracle polling approach
	PollingInterval time.Duration

	// Table name for Oracle polling notifications
	PollingTableName string
}

Config holds configuration for the notification service

func DefaultConfig

func DefaultConfig(databaseType string) Config

DefaultConfig returns a default configuration

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database

const (
	// DatabaseTypePostgres represents PostgreSQL database
	DatabaseTypePostgres DatabaseType = "postgres"
	// DatabaseTypeOracle represents Oracle database
	DatabaseTypeOracle DatabaseType = "oracle"
)

type Notification

type Notification struct {
	// Channel is the notification channel name
	Channel string

	// Payload contains the notification data (typically JSON)
	Payload string

	// Timestamp when the notification was received or created
	Timestamp time.Time
}

Notification represents a database notification event

type NotificationQueueEntry

type NotificationQueueEntry struct {
	ID        models.DBVarchar `gorm:"primaryKey;not null;size:36"`
	Channel   models.DBVarchar `gorm:"size:255;not null;index"`
	Payload   models.DBText    `gorm:""`
	CreatedAt time.Time        `gorm:"not null;autoCreateTime"`
	Processed bool             `gorm:"default:false;not null;index"`
}

NotificationQueueEntry represents an entry in the notification polling table.

This model would be Oracle-reachable once wired up: factory.go's NewNotificationService selects PollingNotifier (not the Postgres LISTEN/NOTIFY notifier) whenever the configured database is Oracle. As of this fix, no other package imports api/notifications, so the polling path is not exercised by the running server today — but the fix belongs here regardless, both because it's the correct behavior and to keep this file honest for whoever wires it up next. Deliberately NOT tagged with `gorm:"column:..."`: result-set labels come back UPPERCASE from Oracle and lowercase from Postgres, and GORM matches labels to DBNames case-sensitively. An untagged field's DBName comes from the dialect's NamingStrategy (OracleNamingStrategy on Oracle), so the mapping holds on both engines; hardcoded lowercase tags silently zeroed every field on Oracle (#699).

func (NotificationQueueEntry) TableName

func (NotificationQueueEntry) TableName() string

TableName specifies the table name for NotificationQueueEntry

type NotificationService

type NotificationService interface {
	// Subscribe starts listening for notifications on the specified channel.
	// It returns a channel that will receive notifications.
	// The caller should handle errors returned in the notifications channel's close.
	Subscribe(ctx context.Context, channel string) (<-chan Notification, error)

	// Notify sends a notification on the specified channel.
	// For PostgreSQL, this uses pg_notify.
	// For Oracle, this inserts into a polling table.
	Notify(ctx context.Context, channel string, payload string) error

	// Close cleans up resources used by the notification service
	Close() error
}

NotificationService defines the interface for database notifications This abstraction allows the application to work with both PostgreSQL's LISTEN/NOTIFY mechanism and Oracle's polling-based approach.

func NewNotificationService

func NewNotificationService(dbType DatabaseType, postgresConnStr string, db *sql.DB, gormDB *gorm.DB) (NotificationService, error)

NewNotificationService creates a notification service appropriate for the database type

func NewNotificationServiceFromConfig

func NewNotificationServiceFromConfig(cfg Config, db *sql.DB, gormDB *gorm.DB) (NotificationService, error)

NewNotificationServiceFromConfig creates a notification service from configuration

type PollingNotifier

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

PollingNotifier implements NotificationService using database polling This is used for Oracle ADB and other databases that don't support LISTEN/NOTIFY

func NewPollingNotifier

func NewPollingNotifier(db *gorm.DB, pollInterval time.Duration) (*PollingNotifier, error)

NewPollingNotifier creates a new polling-based notification service

func (*PollingNotifier) Close

func (p *PollingNotifier) Close() error

Close implements NotificationService.Close

func (*PollingNotifier) Notify

func (p *PollingNotifier) Notify(ctx context.Context, channel string, payload string) error

Notify implements NotificationService.Notify

func (*PollingNotifier) Subscribe

func (p *PollingNotifier) Subscribe(ctx context.Context, channel string) (<-chan Notification, error)

Subscribe implements NotificationService.Subscribe

type PostgresNotifier

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

PostgresNotifier implements NotificationService using PostgreSQL's LISTEN/NOTIFY

func NewPostgresNotifier

func NewPostgresNotifier(connStr string, db *sql.DB) (*PostgresNotifier, error)

NewPostgresNotifier creates a new PostgreSQL notification service

func (*PostgresNotifier) Close

func (p *PostgresNotifier) Close() error

Close implements NotificationService.Close

func (*PostgresNotifier) Notify

func (p *PostgresNotifier) Notify(ctx context.Context, channel string, payload string) error

Notify implements NotificationService.Notify

func (*PostgresNotifier) Subscribe

func (p *PostgresNotifier) Subscribe(ctx context.Context, channel string) (<-chan Notification, error)

Subscribe implements NotificationService.Subscribe

Jump to

Keyboard shortcuts

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