operation

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: AGPL-3.0 Imports: 6 Imported by: 4

Documentation

Overview

Package operation manages operation ids

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelOtherWithLabel

func CancelOtherWithLabel(ctx context.Context, label string)

CancelOtherWithLabel will cancel all operations besides this one with this label. if no Operation is set, will do nothing.

Types

type IsPoweredInterface

type IsPoweredInterface interface {
	IsPowered(ctx context.Context, extra map[string]interface{}) (bool, error)
}

IsPoweredInterface is a utility so can wait on IsPowered easily.

type Manager

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

Manager holds Operations.

func NewManager

func NewManager() *Manager

NewManager creates a new manager for holding Operations.

func (*Manager) All

func (m *Manager) All() []*Operation

All returns all running operations.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, method string, args interface{}) (context.Context, func())

Create puts an operation on this context.

func (*Manager) Find

func (m *Manager) Find(id uuid.UUID) *Operation

Find an Operation.

func (*Manager) FindString

func (m *Manager) FindString(id string) *Operation

FindString an Operation.

type Operation

type Operation struct {
	ID        uuid.UUID
	Method    string
	Arguments interface{}
	Started   time.Time
	// contains filtered or unexported fields
}

Operation is an operation happening on the server.

func Get

func Get(ctx context.Context) *Operation

Get returns the current Operation. This can be nil.

func (*Operation) Cancel

func (o *Operation) Cancel()

Cancel cancel the context associated with an operation.

func (*Operation) CancelOtherWithLabel

func (o *Operation) CancelOtherWithLabel(label string)

CancelOtherWithLabel will cancel all operations besides this one with this label.

func (*Operation) HasLabel

func (o *Operation) HasLabel(label string) bool

HasLabel returns true if this oepration has a speficic label.

type SingleOperationManager

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

SingleOperationManager ensures only 1 operation is happening a time An operation can be nested, so if there is already an operation in progress, it can have sub-operations without an issue.

func (*SingleOperationManager) CancelRunning

func (sm *SingleOperationManager) CancelRunning(ctx context.Context)

CancelRunning cancel's a current operation unless it's mine.

func (*SingleOperationManager) New

func (sm *SingleOperationManager) New(ctx context.Context) (context.Context, func())

New creates a new operation, cancels previous, returns a new context and function to call when done.

func (*SingleOperationManager) NewTimedWaitOp

func (sm *SingleOperationManager) NewTimedWaitOp(ctx context.Context, dur time.Duration) bool

NewTimedWaitOp returns true if it finished, false if cancelled. If there are other operations pending, this will cancel them.

func (*SingleOperationManager) OpRunning

func (sm *SingleOperationManager) OpRunning() bool

OpRunning returns if there is a current operation.

func (*SingleOperationManager) WaitForSuccess

func (sm *SingleOperationManager) WaitForSuccess(
	ctx context.Context,
	pollTime time.Duration,
	testFunc func(ctx context.Context) (bool, error),
) error

WaitForSuccess will call testFunc every pollTime until it returns true or an error.

func (*SingleOperationManager) WaitTillNotPowered

func (sm *SingleOperationManager) WaitTillNotPowered(ctx context.Context, pollTime time.Duration, powered IsPoweredInterface) error

WaitTillNotPowered waits until IsPowered returns false.

Jump to

Keyboard shortcuts

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