operations

package
v0.0.0-...-d2438c5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Interval = 60

Interval represents the number of seconds to wait between to operational GC rounds.

View Source
const (
	// Task represents a Operation classification
	Task class = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Changer

type Changer interface {
	// Dispatch an event to other nodes
	Change(Op)
}

Changer notifies other listeners whom might be listening for operational changes

type Cluster

type Cluster interface {
	database.DBAccessor
	db.ClusterOpener
	db.ClusterTransactioner
	db.ClusterExclusiveLocker

	// NodeID sets the the node NodeID associated with this cluster instance. It's used for
	// backward-compatibility of all db-related APIs that were written before
	// clustering and don't accept a node NodeID, so in those cases we automatically
	// use this value as implicit node NodeID.
	NodeID(int64)

	// Close the database facade.
	Close() error
}

Cluster mediates access to data stored in the cluster dqlite database.

type Op

type Op struct {
	ID         string
	Class      string
	Status     string
	StatusCode Status
	URL        string
	Err        string
}

Op defines a very lightweight operation

type Operation

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

Operation defines a operation that can be run in the background

func NewOperation

func NewOperation(hook func(*Operation) error, changer Changer, options ...Option) *Operation

NewOperation creates an operation with sane defaults

func (*Operation) Cancel

func (o *Operation) Cancel() (<-chan error, error)

Cancel the operation

func (*Operation) IsFinal

func (o *Operation) IsFinal() bool

IsFinal returns the state of the operation

func (*Operation) Render

func (o *Operation) Render() Op

Render the operation as a readonly Op

func (*Operation) Run

func (o *Operation) Run() (<-chan error, error)

Run the operation hook

func (*Operation) Wait

func (o *Operation) Wait(timeout time.Duration) (bool, error)

Wait for an operation to be completed

type Operations

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

Operations represents a operational collection of things that want to be run

func New

func New(cluster Cluster, options ...Option) *Operations

New creates a series of operations to be worked on

func (*Operations) Add

func (o *Operations) Add(op *Operation) error

Add an operation to the collection

func (*Operations) DeleteOp

func (o *Operations) DeleteOp(id string) error

DeleteOp attempts to kill an operation by the id

func (*Operations) GetOpByID

func (o *Operations) GetOpByID(id string) (Op, error)

GetOpByID retrieves an op of the operation from the collection by id

func (*Operations) GetOpByPartialID

func (o *Operations) GetOpByPartialID(id string) (Op, error)

GetOpByPartialID retrieves an op of the operation from the collection by a partial id. As long as the prefix matches an id then it will return that operation. If the id matches multiple ids then it will return an ambiguous error.

func (*Operations) Remove

func (o *Operations) Remove(id string) error

Remove an operation from the collection

func (*Operations) Run

func (o *Operations) Run() (task.Func, task.Schedule)

Run returns a task function that performs operational GC checks against the internal cache of operations.

func (*Operations) WaitOp

func (o *Operations) WaitOp(id string, timeout time.Duration) (bool, error)

WaitOp for an operation to be completed

func (*Operations) Walk

func (o *Operations) Walk(fn func(Op) error) error

Walk over the operations in a predictable manor

type Option

type Option func(*options)

Option to be passed to Connect to customize the resulting instance.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger on the option

type Status

type Status int

Status defines the operatoring status.

const (
	// Pending status operation
	Pending Status = iota
	// Running status operation
	Running
	// Cancelling status operation
	Cancelling
	// Failure status operation
	Failure
	// Success status operation
	Success
	// Cancelled status operation
	Cancelled
)

func (Status) IsFinal

func (s Status) IsFinal() bool

IsFinal will return true if the status code indicates an end state

func (Status) Raw

func (s Status) Raw() int

Raw returns the underlying value

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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