operations

package
v0.0.0-...-49f7de5 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
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
)

Variables

This section is empty.

Functions

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 Operations

func Operations() map[string]*Operation

Operations returns a map of operations.

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, project string, opClass operationClass, opType db.OperationType, opResources map[string][]string, opMetadata interface{}, onRun func(*Operation) error, onCancel func(*Operation) error, onConnect func(*Operation, *http.Request, http.ResponseWriter) error) (*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) 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) ID

func (op *Operation) ID() string

ID returns the operation ID.

func (*Operation) Metadata

func (op *Operation) Metadata() map[string]interface{}

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.

func (*Operation) Resources

func (op *Operation) Resources() map[string][]string

Resources returns the operation resources.

func (*Operation) Run

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

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

func (*Operation) SetCanceler

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

SetCanceler sets a canceler.

func (*Operation) SetEventServer

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

SetEventServer allows injection of event server.

func (*Operation) Status

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

Status returns the operation status.

func (*Operation) URL

func (op *Operation) URL() string

URL returns the operation URL.

func (*Operation) UpdateMetadata

func (op *Operation) UpdateMetadata(opMetadata interface{}) 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][]string) 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) WaitFinal

func (op *Operation) WaitFinal(timeout int) (bool, error)

WaitFinal waits for the operation to be done. If timeout is -1, it will wait indefinitely otherwise it will timeout after {timeout} seconds.

Jump to

Keyboard shortcuts

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