Documentation ¶
Overview ¶
Package operation manages operation ids
Index ¶
- func CancelOtherWithLabel(ctx context.Context, label string)
- func GetOrCreateFromMetadata(meta metadata.MD) (uuid.UUID, error)
- func StreamClientInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, ...) (grpc.ClientStream, error)
- func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- type IsPoweredInterface
- type Manager
- func (m *Manager) All() []*Operation
- func (m *Manager) Create(ctx context.Context, method string, args interface{}) (context.Context, func())
- func (m *Manager) CreateFromIncomingContext(ctx context.Context, method string) (context.Context, func())
- func (m *Manager) Find(id uuid.UUID) *Operation
- func (m *Manager) FindString(id string) *Operation
- func (m *Manager) StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func (m *Manager) UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- type Operation
- type SingleOperationManager
- func (sm *SingleOperationManager) CancelRunning(ctx context.Context)
- func (sm *SingleOperationManager) New(ctx context.Context) (context.Context, func())
- func (sm *SingleOperationManager) NewTimedWaitOp(ctx context.Context, dur time.Duration) bool
- func (sm *SingleOperationManager) OpRunning() bool
- func (sm *SingleOperationManager) WaitForSuccess(ctx context.Context, pollTime time.Duration, ...) error
- func (sm *SingleOperationManager) WaitTillNotPowered(ctx context.Context, pollTime time.Duration, powered IsPoweredInterface, ...) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CancelOtherWithLabel ¶
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
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 ¶
NewManager creates a new manager for holding 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) FindString ¶
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 (*Operation) Cancel ¶
func (o *Operation) Cancel()
Cancel cancel the context associated with an operation.
func (*Operation) CancelOtherWithLabel ¶
CancelOtherWithLabel will cancel all operations besides this one with this label.
type SingleOperationManager ¶
type SingleOperationManager struct {
// contains filtered or unexported fields
}
SingleOperationManager ensures only 1 operation is happening at a time. An operation can be nested, so if there is already an operation in progress, it can have sub-operations.
func NewSingleOperationManager ¶ added in v0.7.3
func NewSingleOperationManager() *SingleOperationManager
NewSingleOperationManager creates a new SingleOperationManager. Use this to appropriately initialize the members.
func (*SingleOperationManager) CancelRunning ¶
func (sm *SingleOperationManager) CancelRunning(ctx context.Context)
CancelRunning cancels 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 ¶
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.