notifications

package
v2.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	WebsocketNotificationReceiptTimeMetric = "notification_websocket_receipt_time"
	SMTPNotificationReceiptTimeMetric      = "notification_smtp_receipt_time"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SessionToken authenticates the runner as PreCreatedUser.
	SessionToken string `json:"-"`

	// PreCreatedUser is the existing user to run as. It must already hold any
	// role needed to receive the notifications under test. Only ID, Username and
	// Email are used.
	PreCreatedUser codersdk.User `json:"-"`

	// NotificationTimeout is how long to wait for notifications after triggering.
	NotificationTimeout time.Duration `json:"notification_timeout"`

	// DialTimeout is how long to wait for websocket connection.
	DialTimeout time.Duration `json:"dial_timeout"`

	// IsTemplateAdmin marks a runner that watches for and counts notifications.
	// Regular users leave it false and only hold a websocket connection open.
	IsTemplateAdmin bool `json:"-"`

	// ExpectedDeletions is how many TemplateTemplateDeleted notifications a
	// template admin waits for (one per template deletion). It is ignored unless
	// IsTemplateAdmin is set, in which case it must be at least 1.
	ExpectedDeletions int `json:"-"`

	Metrics *Metrics `json:"-"`

	// DialBarrier ensures all runners are connected before notifications are triggered.
	DialBarrier *sync.WaitGroup `json:"-"`

	// ReceivingWatchBarrier is the barrier for receiving users. Regular users wait on this to disconnect after receiving users complete.
	ReceivingWatchBarrier *sync.WaitGroup `json:"-"`

	// SMTPApiUrl is the URL of the SMTP mock HTTP API
	SMTPApiURL string `json:"smtp_api_url"`

	// SMTPRequestTimeout is the timeout for SMTP requests.
	SMTPRequestTimeout time.Duration `json:"smtp_request_timeout"`

	// SMTPHttpClient is the HTTP client for SMTP requests.
	SMTPHttpClient *http.Client `json:"-"`
}

func (Config) Validate

func (c Config) Validate() error

type Metrics

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

func NewMetrics

func NewMetrics(reg prometheus.Registerer) *Metrics

func (*Metrics) AddError

func (m *Metrics) AddError(action string)

func (*Metrics) RecordLatency

func (m *Metrics) RecordLatency(latency time.Duration, notificationID string, notificationType NotificationType)

type NotificationType

type NotificationType string
const (
	NotificationTypeWebsocket NotificationType = "websocket"
	NotificationTypeSMTP      NotificationType = "smtp"
)

type Runner

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

func NewRunner

func NewRunner(client *codersdk.Client, cfg Config) *Runner

func (*Runner) Cleanup

func (*Runner) Cleanup(_ context.Context, _ string, _ io.Writer) error

func (*Runner) GetMetrics

func (r *Runner) GetMetrics() map[string]any

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) error

func (*Runner) WithClock

func (r *Runner) WithClock(clock quartz.Clock) *Runner

Jump to

Keyboard shortcuts

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