notify

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package notify is an experiment for sending notifications.

Index

Constants

View Source
const (
	Created   = State("CREATED")
	Running   = State("RUNNING")
	Completed = State("COMPLETED")
	Canceled  = State("CANCELED")
	Failed    = State("FAILED")
)

Possible values of State.

Variables

This section is empty.

Functions

func RegisterProvider

func RegisterProvider(typ DestType, p Provider)

RegisterProvider should be invoked by notification implementations to indicate that they handle a specific destination type.

func ValidHandle

func ValidHandle(handle string) error

ValidHandle returns an error if handle is not an acceptable notification destination handle value.

Types

type AsyncNotifier

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

AsyncNotifier is a Notifier that wraps a bunch of other notifiers and sends message asynchronously. The invoking code should call AsyncNotifier.Wait() before exiting.

func NewAsyncNotifier

func NewAsyncNotifier(log lg.Log, dests []Destination) (*AsyncNotifier, error)

NewAsyncNotifier returns a Notifier that sends messages asynchronously to the supplied destination. The invoking code should call AsyncNotifier.Wait() before exiting. TODO: Should take a context.Context param.

func (*AsyncNotifier) Send

func (a *AsyncNotifier) Send(msg Message) error

func (*AsyncNotifier) Wait

func (a *AsyncNotifier) Wait(timeout time.Duration)

type DestType

type DestType string

DestType is the destination type, e.g. "slack", "hipchat", or "email" etc.

type Destination

type Destination struct {
	Type        DestType `yaml:"type" json:"type"`
	Label       string   `yaml:"label" json:"label"`
	Target      string   `yaml:"target" json:"target"`
	Credentials string   `yaml:"credentials" json:"credentials"`
}

Destination is a destination for messages.

func (Destination) String

func (d Destination) String() string

type Job

type Job struct {
	ID      string     `yaml:"id" json:"id"`
	Started *time.Time `yaml:"started,omitempty" json:"started,omitempty"`
	Ended   *time.Time `yaml:"ended,omitempty" json:"ended,omitempty"`

	// Stmt is the SLQ/SQL statement/query this job is executing.
	Stmt   string  `yaml:"stmt" json:"stmt"`
	State  State   `yaml:"state" json:"state"`
	Errors []error `yaml:"errors,omitempty" json:"errors,omitempty"`
}

Job represents a single libsq engine workflow instance.

func New

func New(stmt string) *Job

New returns a new Job, with a generated ID, and State set to Created. The Started and Ended fields are both nil.

func (*Job) Complete

func (j *Job) Complete() *Job

Complete sets the job.Ended timestamp, and job.State to Completed.

func (*Job) Fail

func (j *Job) Fail(errs ...error) *Job

Fail sets the job.Ended timestamp, job.State to Failed, and adds the provided errors to job.Errors

func (*Job) Start

func (j *Job) Start() *Job

Start sets the job.Started timestamp, and job.State to Running.

func (*Job) String

func (j *Job) String() string

type Message

type Message struct {
	Text string `yaml:"text" json:"text"`
	Job  *Job   `yaml:"job,empty" json:"job,omitempty"`
}

Message is a notification message, optionally containing a Job that the message is associated with.

func NewJobMessage

func NewJobMessage(jb Job) Message

NewJobMessage creates a Message indicating the state of the job.

type Notifier

type Notifier interface {
	// Send sends the message.
	Send(msg Message) error
}

Notifier is an interface that can send notification messages.

type Provider

type Provider interface {
	// Destination returns a notification Destination instance from the supplied parameters.
	Destination(typ DestType, target string, label string, credentials string, labelAvailable func(label string) bool) (*Destination, error)
	// Notifier returns a Notifier instance for the given destination.
	Notifier(dest Destination) (Notifier, error)
}

Provider is a factory that returns Notifier instances and generates notification Destinations from user parameters.

func ProviderFor

func ProviderFor(typ DestType) (Provider, error)

ProviderFor returns a Provider for the specified destination type.

type State

type State string

State is the job state, one of Created, Running, Completed or Failed.

Jump to

Keyboard shortcuts

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