notification

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultPayloadContentType represents the default content type used for
	// webhooks notifications.
	DefaultPayloadContentType = "application/cloudevents+json"
)

Variables

View Source
var DefaultWebhookPayloadTmpl = template.Must(template.New("").Parse(`
{
	"specversion" : "1.0",
	"id" : "{{ .Event.ID }}",
	"source" : "{{ .BaseURL }}",
	"type" : "io.artifacthub.{{ .Event.Kind }}",
	"datacontenttype" : "application/json",
	"data" : {
		"package": {
			"name": "{{ .Package.Name }}",
			"version": "{{ .Package.Version }}",
			"url": "{{ .Package.URL }}",
			"changes": [{{range $i, $e := .Package.Changes}}{{if $i}}, {{end}}"{{.Description}}"{{end}}],
			"containsSecurityUpdates": {{ .Package.ContainsSecurityUpdates }},
			"prerelease": {{ .Package.Prerelease }},
			"repository": {
				"kind": "{{ .Package.Repository.Kind }}",
				"name": "{{ .Package.Repository.Name }}",
				"publisher": "{{ .Package.Repository.Publisher }}"
			}
		}
	}
}
`))

DefaultWebhookPayloadTmpl is the template used for the webhook payload when the webhook uses the default template.

View Source
var (
	// ErrRetryable is meant to be used as a wrapper for other errors to
	// indicate the error is not final and the operation should be retried.
	ErrRetryable = errors.New("retryable error")
)

Functions

func WithNumWorkers

func WithNumWorkers(n int) func(d *Dispatcher)

WithNumWorkers allows providing a specific number of workers for a Dispatcher instance.

Types

type Dispatcher

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

Dispatcher handles a group of workers in charge of delivering notifications.

func NewDispatcher

func NewDispatcher(svc *Services, opts ...func(d *Dispatcher)) *Dispatcher

NewDispatcher creates a new Dispatcher instance.

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context, wg *sync.WaitGroup)

Run starts the workers and lets them run until the dispatcher is asked to stop via the context provided.

type Manager

type Manager struct{}

Manager provides an API to manage notifications.

func NewManager

func NewManager() *Manager

NewManager creates a new Manager instance.

func (*Manager) Add

func (m *Manager) Add(ctx context.Context, tx pgx.Tx, n *hub.Notification) error

Add adds the provided notification to the database.

func (*Manager) GetPending

func (m *Manager) GetPending(ctx context.Context, tx pgx.Tx) (*hub.Notification, error)

GetPending returns a pending notification to be delivered if available.

func (*Manager) UpdateStatus

func (m *Manager) UpdateStatus(
	ctx context.Context,
	tx pgx.Tx,
	notificationID string,
	processed bool,
	processedErr error,
) error

UpdateStatus the provided notification status in the database.

type ManagerMock

type ManagerMock struct {
	mock.Mock
}

ManagerMock is a mock implementation of the NotificationManager interface.

func (*ManagerMock) Add

func (m *ManagerMock) Add(ctx context.Context, tx pgx.Tx, n *hub.Notification) error

Add implements the NotificationManager interface.

func (*ManagerMock) GetPending

func (m *ManagerMock) GetPending(ctx context.Context, tx pgx.Tx) (*hub.Notification, error)

GetPending implements the NotificationManager interface.

func (*ManagerMock) UpdateStatus

func (m *ManagerMock) UpdateStatus(
	ctx context.Context,
	tx pgx.Tx,
	notificationID string,
	processed bool,
	processedErr error,
) error

UpdateStatus implements the NotificationManager interface.

type Services

type Services struct {
	Cfg                 *viper.Viper
	DB                  hub.DB
	ES                  hub.EmailSender
	NotificationManager hub.NotificationManager
	SubscriptionManager hub.SubscriptionManager
	RepositoryManager   hub.RepositoryManager
	PackageManager      hub.PackageManager
	HTTPClient          hub.HTTPClient
}

Services is a wrapper around several internal services used to handle notifications deliveries.

type Worker

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

Worker is in charge of delivering notifications to their intended recipients.

func NewWorker

func NewWorker(
	svc *Services,
	c *cache.Cache,
	tmpl map[templateID]*template.Template,
) *Worker

NewWorker creates a new Worker instance.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context, wg *sync.WaitGroup)

Run is the main loop of the worker. It calls processNotification periodically until it's asked to stop via the context provided.

Jump to

Keyboard shortcuts

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