Help us shape the future of Go! Take the 2026 Go Developer Survey

notify

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package notify provides PostgreSQL LISTEN/NOTIFY functionality for real-time notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

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

Listener manages PostgreSQL LISTEN/NOTIFY connections.

func NewListener

func NewListener(connString string, opts ...ListenerOption) *Listener

NewListener creates a new PostgreSQL notification listener.

func (*Listener) IsActive

func (l *Listener) IsActive() bool

IsActive returns true if the LISTEN/NOTIFY connection is active.

func (*Listener) LastError

func (l *Listener) LastError() error

LastError returns the last connection error, if any.

func (*Listener) OnNotification

func (l *Listener) OnNotification(channel NotifyChannel, handler NotificationHandler)

OnNotification registers a handler for a notification channel. Multiple handlers can be registered for the same channel.

func (*Listener) Start

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

Start begins listening in the background. A listener may be restarted after Stop completes.

func (*Listener) Stop

func (l *Listener) Stop(ctx context.Context) error

Stop cancels the listener and waits for its connection and handlers to finish.

type ListenerOption

type ListenerOption func(*Listener)

ListenerOption configures a Listener.

func WithReconnectDelay

func WithReconnectDelay(d time.Duration) ListenerOption

WithReconnectDelay sets the delay before reconnecting after a connection failure.

type NotificationHandler

type NotificationHandler func(ctx context.Context, channel NotifyChannel, payload string)

NotificationHandler is a callback function that handles notifications.

type NotifyChannel

type NotifyChannel string

NotifyChannel represents a PostgreSQL notification channel name.

const (
	// ChannelWorkflowClosed wakes clients awaiting terminal results.
	ChannelWorkflowClosed NotifyChannel = "workflow_closed"
	// ChannelActivityTask wakes workers when activity work becomes available.
	ChannelActivityTask NotifyChannel = "workflow_activity_task"
	// ChannelWorkflowResumable is notified when a workflow becomes resumable.
	ChannelWorkflowResumable NotifyChannel = "workflow_resumable"
	// ChannelTimerExpired is notified when a timer is registered.
	ChannelTimerExpired NotifyChannel = "workflow_timer_expired"
)

func AllChannels

func AllChannels() []NotifyChannel

AllChannels returns all notification channels.

type TimerNotification

type TimerNotification struct {
	InstanceID string `json:"instance_id"`
	TimerID    string `json:"timer_id"`
	ExpiresAt  string `json:"expires_at,omitempty"`
}

TimerNotification is the payload for timer expired notifications.

func ParseTimerNotification

func ParseTimerNotification(payload string) (*TimerNotification, error)

ParseTimerNotification parses a timer notification payload.

type WorkflowNotification

type WorkflowNotification struct {
	InstanceID   string `json:"instance_id"`
	WorkflowName string `json:"workflow_name,omitempty"`
}

WorkflowNotification is the payload for workflow resumable notifications.

func ParseWorkflowNotification

func ParseWorkflowNotification(payload string) (*WorkflowNotification, error)

ParseWorkflowNotification parses a workflow notification payload.

Jump to

Keyboard shortcuts

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