Documentation
¶
Overview ¶
Package operation provides implementation for handling operations in Yandex Cloud Go SDK.
An operation represents a long-running task in Yandex Cloud that can be monitored and managed through this package. Operations are typically created by service methods and can be polled for completion status.
Usage Example:
op, err := service.CreateResource(ctx, request)
if err != nil {
// handle error
}
// Wait for operation completion
result, err := op.Wait(ctx)
if err != nil {
// handle error
}
Index ¶
- func Error(op YCOperation) error
- func Response(op YCOperation) (proto.Message, error)
- type AbstractOperation
- type Concretization
- type Operation
- func (o *Operation) Abstract() AbstractOperation
- func (o *Operation) CreatedAt() time.Time
- func (o *Operation) CreatedBy() string
- func (o *Operation) Description() string
- func (o *Operation) Done() bool
- func (o *Operation) Error() error
- func (o *Operation) ID() string
- func (o *Operation) Metadata() proto.Message
- func (o *Operation) PollOnce(ctx context.Context, opts ...grpc.CallOption) error
- func (o *Operation) ResourceID() string
- func (o *Operation) Response() proto.Message
- func (o *Operation) Result() OperationResult
- func (o *Operation) Wait(ctx context.Context, opts ...grpc.CallOption) (proto.Message, error)
- func (o *Operation) WaitInterval(ctx context.Context, pollInterval PollIntervalFunc, opts ...grpc.CallOption) (proto.Message, error)
- type OperationResult
- type PollFunc
- type PollIntervalFunc
- type YCOperation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(op YCOperation) error
Error extracts and returns the error from the provided YCOperation if it exists, otherwise returns nil.
Types ¶
type AbstractOperation ¶
type AbstractOperation interface {
ID() string
Description() string
CreatedBy() string
CreatedAt() time.Time
Metadata() proto.Message
ResourceID() string
Done() bool
PollOnce(ctx context.Context, opts ...grpc.CallOption) error
Wait(ctx context.Context, opts ...grpc.CallOption) (proto.Message, error)
Error() error
Response() proto.Message
Result() OperationResult
}
type Concretization ¶
type Concretization struct {
Poll PollFunc
MetadataType proto.Message
ResponseType proto.Message
GetResourceID func(metadata proto.Message) string
}
Concretization is a type that defines the operation handling behavior for polling and response management. Poll is a function for retrieving operation information from an operation service. MetadataType specifies the protobuf message type for the operation's metadata. ResponseType specifies the protobuf message type for the operation's response. GetResourceID is a function to extract a resource ID from the metadata.
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation represents an operation instance with associated metadata, response, and error handling functionality.
func NewOperation ¶
func NewOperation(pb YCOperation, concretization *Concretization) (*Operation, error)
NewOperation creates a new Operation instance based on the provided YCOperation and Concretization parameters. Returns an Operation instance and an error if the metadata type does not match or other issues arise.
func (*Operation) Abstract ¶
func (o *Operation) Abstract() AbstractOperation
Abstract returns the current operation as an AbstractOperation, providing access to its abstract interface.
func (*Operation) CreatedAt ¶
CreatedAt returns the creation timestamp of the operation as a time.Time object.
func (*Operation) CreatedBy ¶
CreatedBy returns the identifier of the entity that created the operation.
func (*Operation) Description ¶
Description returns a string that provides the description of the operation based on the underlying proto definition.
func (*Operation) Done ¶
Done checks if the operation has been completed and returns true if it is done, otherwise false.
func (*Operation) Error ¶
Error returns the error encountered during the operation, prioritizing the responseError if available.
func (*Operation) Metadata ¶
Metadata retrieves the metadata associated with the Operation. It returns a proto.Message representing the metadata.
func (*Operation) PollOnce ¶
PollOnce performs a single polling attempt to update the operation's state and metadata in place. Returns an error if polling fails.
func (*Operation) ResourceID ¶
ResourceID retrieves the resource ID associated with the operation's metadata or panics if not defined.
func (*Operation) Response ¶
Response returns the response of the completed operation. Panics if the operation is not completed or has errors.
func (*Operation) Result ¶
func (o *Operation) Result() OperationResult
Result returns the result of the operation if it has completed. Panics if the operation is not yet done.
func (*Operation) Wait ¶
Wait blocks until the operation is completed or the context is canceled, returning the operation's response or an error.
func (*Operation) WaitInterval ¶
func (o *Operation) WaitInterval( ctx context.Context, pollInterval PollIntervalFunc, opts ...grpc.CallOption, ) (proto.Message, error)
WaitInterval polls the operation periodically until it is complete or the context is canceled, using a custom interval.
type OperationResult ¶
type PollFunc ¶
type PollFunc func(ctx context.Context, operationId string, opts ...grpc.CallOption) (YCOperation, error)
PollFunc defines a function type used to poll the status of an operation using its ID and return a YCOperation or an error.
type PollIntervalFunc ¶
PollIntervalFunc defines a function type that calculates the delay between polling attempts based on the attempt number.
type YCOperation ¶
type YCOperation interface {
GetId() string
GetDescription() string
GetMetadata() *anypb.Any
GetCreatedAt() *timestamppb.Timestamp
GetError() *status.Status
GetCreatedBy() string
GetResponse() *anypb.Any
GetDone() bool
ProtoReflect() protoreflect.Message
}
func PollUntilDone ¶
func PollUntilDone( ctx context.Context, operationId string, poll PollFunc, pollInterval PollIntervalFunc, opts ...grpc.CallOption, ) (YCOperation, error)
PollUntilDone repeatedly polls the status of a long-running operation until it is marked as done or the context is canceled. ctx is the context for managing the polling lifecycle and cancellation. operationId identifies the specific operation to be polled. poll is a function used to fetch the current state of the operation. pollInterval determines the duration to wait between polling attempts based on the attempt count. opts allows for additional gRPC call options to be passed during polling. Returns the completed YCOperation or an error if polling fails or the context is canceled.