operations

package
v0.0.0-...-288c4de Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone() map[string]*Operation

Clone returns a clone of the internal operations map containing references to the actual operations.

func ForwardedOperationResponse

func ForwardedOperationResponse(project string, op *api.Operation) response.Response

ForwardedOperationResponse creates a response that forwards the metadata of an operation created on another node.

func ForwardedOperationWebSocket

func ForwardedOperationWebSocket(req *http.Request, id string, source *websocket.Conn) response.Response

ForwardedOperationWebSocket returns a new forwarted websocket operation.

func Init

func Init(d bool)

Init sets the debug value for the operations package.

func Lock

func Lock()

Lock locks the operations mutex.

func OperationResponse

func OperationResponse(op *Operation) response.Response

OperationResponse returns an operation response.

func OperationWebSocket

func OperationWebSocket(req *http.Request, op *Operation) response.Response

OperationWebSocket returns a new websocket operation.

func Unlock

func Unlock()

Unlock unlocks the operations mutex.

Types

type Operation

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

Operation represents an operation.

func OperationCreate

func OperationCreate(s *state.State, projectName string, opClass OperationClass, opType operationtype.Type, opResources map[string][]api.URL, opMetadata any, onRun func(*Operation) error, onCancel func(*Operation) error, onConnect func(*Operation, *http.Request, http.ResponseWriter) error, r *http.Request) (*Operation, error)

OperationCreate creates a new operation and returns it. If it cannot be created, it returns an error.

func OperationGetInternal

func OperationGetInternal(id string) (*Operation, error)

OperationGetInternal returns the operation with the given id. It returns an error if it doesn't exist.

func (*Operation) Cancel

func (op *Operation) Cancel() (chan error, error)

Cancel cancels a running operation. If the operation cannot be cancelled, it returns an error.

func (*Operation) Class

func (op *Operation) Class() OperationClass

Class returns the operation class.

func (*Operation) Connect

func (op *Operation) Connect(r *http.Request, w http.ResponseWriter) (chan error, error)

Connect connects a websocket operation. If the operation is not a websocket operation or the operation is not running, it returns an error.

func (*Operation) ExtendMetadata

func (op *Operation) ExtendMetadata(metadata any) error

ExtendMetadata updates the metadata of the operation with the additional data provided. It returns an error if the operation is not pending or running, or the operation is read-only.

func (*Operation) ID

func (op *Operation) ID() string

ID returns the operation ID.

func (*Operation) Metadata

func (op *Operation) Metadata() map[string]any

Metadata returns the operation Metadata.

func (*Operation) Permission

func (op *Operation) Permission() string

Permission returns the operation permission.

func (*Operation) Project

func (op *Operation) Project() string

Project returns the operation project.

func (*Operation) Render

func (op *Operation) Render() (string, *api.Operation, error)

Render renders the operation structure. Returns URL of operation and operation info.

func (*Operation) Requestor

func (op *Operation) Requestor() *api.EventLifecycleRequestor

Requestor returns the initial requestor for this operation.

func (*Operation) Resources

func (op *Operation) Resources() map[string][]api.URL

Resources returns the operation resources.

func (*Operation) SetCanceler

func (op *Operation) SetCanceler(canceler *cancel.HTTPRequestCanceller)

SetCanceler sets a canceler.

func (*Operation) SetEventServer

func (op *Operation) SetEventServer(events *events.Server)

SetEventServer allows injection of event server.

func (*Operation) SetRequestor

func (op *Operation) SetRequestor(r *http.Request)

SetRequestor sets a requestor for this operation from an http.Request.

func (*Operation) Start

func (op *Operation) Start() error

Start a pending operation. It returns an error if the operation cannot be started.

func (*Operation) Status

func (op *Operation) Status() api.StatusCode

Status returns the operation status.

func (*Operation) Type

func (op *Operation) Type() operationtype.Type

Type returns the db operation type.

func (*Operation) URL

func (op *Operation) URL() string

URL returns the operation URL.

func (*Operation) UpdateMetadata

func (op *Operation) UpdateMetadata(opMetadata any) error

UpdateMetadata updates the metadata of the operation. It returns an error if the operation is not pending or running, or the operation is read-only.

func (*Operation) UpdateResources

func (op *Operation) UpdateResources(opResources map[string][]api.URL) error

UpdateResources updates the resources of the operation. It returns an error if the operation is not pending or running, or the operation is read-only.

func (*Operation) Wait

func (op *Operation) Wait(ctx context.Context) error

Wait for the operation to be done. Returns non-nil error if operation failed or context was cancelled.

type OperationClass

type OperationClass int

OperationClass represents the OperationClass type.

const (
	// OperationClassTask represents the Task OperationClass.
	OperationClassTask OperationClass = 1
	// OperationClassWebsocket represents the Websocket OperationClass.
	OperationClassWebsocket OperationClass = 2
	// OperationClassToken represents the Token OperationClass.
	OperationClassToken OperationClass = 3
)

func (OperationClass) String

func (t OperationClass) String() string

Jump to

Keyboard shortcuts

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