operation

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configure

type Configure func(i *model.InvokedOperation) error

configure the operation

type DryRunFunc

this is so the dry run can be tested, detaching actual dry run implementation

type ExecutionContext

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

Context object for interacting with an operation execution

remarks: flyweight of an Operation

func (*ExecutionContext) Attribute

func (c *ExecutionContext) Attribute(key model.AttributeKey, v any) error

func (*ExecutionContext) Complete

func (c *ExecutionContext) Complete()

func (*ExecutionContext) Context

func (c *ExecutionContext) Context() context.Context

func (*ExecutionContext) Error

func (c *ExecutionContext) Error(err error)

func (*ExecutionContext) Failed

func (c *ExecutionContext) Failed() error

func (*ExecutionContext) Operation

func (c *ExecutionContext) Operation() *Operation

func (*ExecutionContext) Retry

func (c *ExecutionContext) Retry() error

func (*ExecutionContext) Running

func (c *ExecutionContext) Running() error

func (*ExecutionContext) SaveChanges

func (c *ExecutionContext) SaveChanges() error

func (*ExecutionContext) Success

func (c *ExecutionContext) Success()

func (*ExecutionContext) Value

func (c *ExecutionContext) Value(v any) error

type Executor

type Executor interface {
	Execute(context *ExecutionContext) error
}

Executor is the interface for the actual execution of a logically invoked operation from the API Requestor --> invoke this operation --> enqueue --> executor --> execute the operation

func NewExecutor

func NewExecutor(operation OperationFunc) Executor

default operations executor that executions the operation(s) in sequence with logging and default retry logic

remarks: if any of the operations return an error, the executor considers this a failure and will not execute

type Operation

type Operation struct {
	model.InvokedOperation
	// contains filtered or unexported fields
}

remarks: Invoked Operation decorator+visitor

func (*Operation) Attribute

func (o *Operation) Attribute(key model.AttributeKey, v any) error

func (*Operation) Complete

func (o *Operation) Complete() error

func (*Operation) Context

func (o *Operation) Context() context.Context

func (*Operation) Deployment

func (o *Operation) Deployment() *model.Deployment

provides access to latest instance of associated deployment

func (*Operation) Do

func (o *Operation) Do(fn OperationFunc)

sets the operation's execution function

func (*Operation) Execute

func (o *Operation) Execute() error

executes the operation

func (*Operation) Failed

func (o *Operation) Failed() error

func (*Operation) Retry

func (o *Operation) Retry() error

Attempts to trigger a retry of the operation, if the operation has a retriable state

func (*Operation) Running

func (o *Operation) Running() error

func (*Operation) SaveChanges

func (o *Operation) SaveChanges() error

func (*Operation) Schedule

func (o *Operation) Schedule() error

func (*Operation) Success

func (o *Operation) Success() error

func (*Operation) Value

func (o *Operation) Value(v any) error

type OperationFunc

type OperationFunc func(context *ExecutionContext) error

a executable operation with an execution context

func WithLogging

func WithLogging(operation OperationFunc) OperationFunc

type OperationFuncProvider

type OperationFuncProvider interface {
	Get(operationType sdk.OperationType) (OperationFunc, error)
}

type OperationService

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

func NewService

func NewService(db *gorm.DB, sender messaging.MessageSender, notify hook.NotifyFunc) (*OperationService, error)

constructor factory of operation service

func (*OperationService) Context

func (service *OperationService) Context() context.Context

type Repository

type Repository interface {
	New(operationType sdk.OperationType, configure Configure) (*Operation, error)
	First(id uuid.UUID) (*Operation, error)
	Provider(provider OperationFuncProvider) error
	WithContext(ctx context.Context)
}

Operation factory

func NewRepository

func NewRepository(service *OperationService, provider OperationFuncProvider) (Repository, error)

NewRepository creates a new operation factory appConfig: application configuration provider: operation function provider, optional if the operation is not going to be executed and you want to interact with the operation

type RetriableError

type RetriableError struct {
	Err        error
	RetryAfter time.Duration
}

RetriableError is a custom error that contains a positive duration for the next retry

func (*RetriableError) Error

func (e *RetriableError) Error() string

Error returns error message and a Retry-After duration

Jump to

Keyboard shortcuts

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