Documentation ¶
Overview ¶
Package operation manages operation ids
Index ¶
- func CancelOtherWithLabel(ctx context.Context, label string)
- type IsPoweredInterface
- type Manager
- 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) 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.
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) Create ¶
func (m *Manager) Create(ctx context.Context, method string, args interface{}) (context.Context, func())
Create puts an operation on this context.
func (*Manager) FindString ¶
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 (*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 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 ¶
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.