operation

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: AGPL-3.0 Imports: 13 Imported by: 3

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.

func GetOrCreateFromMetadata added in v0.1.5

func GetOrCreateFromMetadata(meta metadata.MD) (uuid.UUID, error)

GetOrCreateFromMetadata returns an operation id from metadata, or generates a random UUID if the metadata does not contain any.

func StreamClientInterceptor added in v0.1.5

func StreamClientInterceptor(
	ctx context.Context,
	desc *grpc.StreamDesc,
	cc *grpc.ClientConn,
	method string,
	streamer grpc.Streamer,
	opts ...grpc.CallOption,
) (grpc.ClientStream, error)

StreamClientInterceptor adds the operation id from the current context (if any) to the outgoing streaming RPC metadata.

func UnaryClientInterceptor added in v0.1.5

func UnaryClientInterceptor(
	ctx context.Context,
	method string,
	req, reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) error

UnaryClientInterceptor adds the operation id from the current context (if any) to the outgoing unary RPC metadata.

Types

type IsPoweredInterface

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

IsPoweredInterface is a utility so can wait on IsPowered easily. It returns whether it is powered, the power percent (between 0 and 1, or between -1 and 1 for motors that support negative power), and any error that occurred while obtaining these.

type Manager

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

Manager holds Operations.

func NewManager

func NewManager(logger golog.Logger) *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) CreateFromIncomingContext added in v0.1.5

func (m *Manager) CreateFromIncomingContext(ctx context.Context, method string) (context.Context, func())

CreateFromIncomingContext creates a new operation from an incoming 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.

func (*Manager) StreamServerInterceptor added in v0.1.5

func (m *Manager) StreamServerInterceptor(
	srv interface{},
	ss grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

StreamServerInterceptor creates a new operation in the current context before passing it to the stream response handler. If the incoming RPC metadata contains an operation ID, the new operation will have the same ID.

func (*Manager) UnaryServerInterceptor added in v0.1.5

func (m *Manager) UnaryServerInterceptor(
	ctx context.Context,
	req interface{},
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (interface{}, error)

UnaryServerInterceptor creates a new operation in the current context before passing it to the unary response handler. If the incoming RPC metadata contains an operation ID, the new operation will have the same ID.

type Operation

type Operation struct {
	ID        uuid.UUID
	SessionID 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 operation has a specific 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,
	stop func(context.Context, map[string]interface{}) error,
) (err 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