broker

package
v0.0.0-...-c0b5b33 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BucketQueue is the outer bucket for other queue-oriented buckets, keyed by resource.
	BucketQueue = "queues"
	// BucketPackages is the outer bucket for all package queues.
	BucketPackages = "packages"
	// BucketCommands is the bucket for all commands.
	BucketCommands = "commands"
	// BucketStatuses is the bucket for all statuses.
	BucketStatuses = "statuses"
)

Variables

View Source
var (
	// ErrRecordNotFound is returned when records are not found. This in
	// particular can happen in scenarios when requesting the status of an object
	// and it is unavailable.
	ErrRecordNotFound = errors.New("Record not found")

	// ErrRecordAlreadyExists is returned when trying to set a status that has
	// already been set.
	ErrRecordAlreadyExists = errors.New("Record already exists")
)

Functions

This section is empty.

Types

type Command

type Command struct {
	dispatcher.Command `json:",inline"`
	Parameters         map[string]interface{} `json:"parameters"`
}

Command is a unit of instruction; it contains a UUID, the unique identifier of the command, a Resource, the type of command to execute, an action, the name of the command to execute, and parameters, a collection of items that relate to the action for the purposes of execution.

Commands are typically fed to Packages, then the Package is Enqueued, Next() calls are made to yield the commands for the resource, the command is processed, FinishCommand is called to finish the command, then statuses are polled and eventually yielded.

type DB

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

DB is our DB handle. It contains a *bbolt.DB handle for internal use.

func New

func New(dbpath string) (*DB, error)

New creates a new database handle. The file is created if it does not already exist with 0600 perms, and some tuning is applied. The outermost buckets are also created at this time if they do not exist.

func (*DB) Close

func (db *DB) Close() error

Close the database.

func (*DB) CommandStatus

func (db *DB) CommandStatus(uuid string) error

CommandStatus returns the status of the Command UUID as an error if faulty, otherwise nil for success.

func (*DB) FinishCommand

func (db *DB) FinishCommand(uuid string, statusResult bool, reason string) error

FinishCommand reports a status for the Command UUID. If the result is true, reason is ignored.

func (*DB) NewPackage

func (db *DB) NewPackage() (*Package, error)

NewPackage creates a new Package and returns it, or error if there was any trouble. It will retry on collisions.

func (*DB) Package

func (db *DB) Package(uuid string) (*Package, error)

Package returns a Package from the provided UUID. If none is found, ErrRecordNotFound is returned.

func (*DB) Queue

func (db *DB) Queue(name string) (*Queue, error)

Queue retrieves the Queue object for the named resource.

type ErrorStatus

type ErrorStatus struct {
	Reason string
	Causer string // UUID of causer
}

ErrorStatus is for status reports that are in an errored state. This includes the reason as well. The type mostly exists to distinguish it from other golang errors.

func (ErrorStatus) Error

func (es ErrorStatus) Error() string

type Package

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

Package is a collection of queue items that are in a waiting or enqueued state as a group.

func (*Package) Add

func (p *Package) Add(value *Command) error

Add adds a Command to the Package. It will be assigned a UUID which is written back to the pointered value. This may be retried. Any error writing to the database or marshaling the values will return an error.

func (*Package) Enqueue

func (p *Package) Enqueue() error

Enqueue enqueues the package in the relevant resource queues.

func (*Package) Finished

func (p *Package) Finished() error

Finished returns non-nil if: - The package is unfinished (ErrRecordNotFound) - The package had errors (ErrorStatus)

Otherwise, it returns nil, which means everything ran fine.

func (*Package) List

func (p *Package) List() ([]Command, error)

List lists the commands for the Package.

func (*Package) UUID

func (p *Package) UUID() string

UUID returns the Package UUID.

type Queue

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

Queue is the notion of a resource-based queue in the broker. These are Command structs separated by resource and organized into order.

func (*Queue) Insert

func (q *Queue) Insert(value Command) error

Insert inserts an item into the Queue.

func (*Queue) Next

func (q *Queue) Next() (c Command, retErr error)

Next returns the next item in the queue, then removes it from the queue.

Jump to

Keyboard shortcuts

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