astiencoder

package module
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusCreated = "created"
	StatusPaused  = "paused"
	StatusRunning = "running"
	StatusStopped = "stopped"
)

Statuses

View Source
const (
	StatNameHostUsage = "astiencoder.host.usage"
)

Variables

View Source
var (
	EventNameError                EventName = "astiencoder.error"
	EventNameNodeChildAdded       EventName = "astiencoder.node.child.added"
	EventNameNodeChildRemoved     EventName = "astiencoder.node.child.removed"
	EventNameNodeClosed           EventName = "astiencoder.node.closed"
	EventNameNodeContinued        EventName = "astiencoder.node.continued"
	EventNameNodePaused           EventName = "astiencoder.node.paused"
	EventNameNodeStarted          EventName = "astiencoder.node.started"
	EventNameNodeStopped          EventName = "astiencoder.node.stopped"
	EventNameStats                EventName = "astiencoder.stats"
	EventNameWorkflowChildAdded   EventName = "astiencoder.workflow.child.added"
	EventNameWorkflowChildRemoved EventName = "astiencoder.workflow.child.removed"
	EventNameWorkflowClosed       EventName = "astiencoder.workflow.closed"
	EventNameWorkflowContinued    EventName = "astiencoder.workflow.continued"
	EventNameWorkflowPaused       EventName = "astiencoder.workflow.paused"
	EventNameWorkflowStarted      EventName = "astiencoder.workflow.started"
	EventNameWorkflowStopped      EventName = "astiencoder.workflow.stopped"
	EventTypeChildAdded           EventType = "child.added"
	EventTypeChildRemoved         EventType = "child.removed"
	EventTypeClosed               EventType = "closed"
	EventTypeContinued            EventType = "continued"
	EventTypePaused               EventType = "paused"
	EventTypeStarted              EventType = "started"
	EventTypeStopped              EventType = "stopped"
)

Default event names

Functions

func ConnectNodes

func ConnectNodes(parent, child Node)

ConnectNodes connects 2 nodes

func DisconnectNodes

func DisconnectNodes(parent, child Node)

DisconnectNodes disconnects 2 nodes

Types

type BaseNode

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

BaseNode represents a base node

func NewBaseNode

func NewBaseNode(o NodeOptions, c *astikit.Closer, eh *EventHandler, s *Stater, target interface{}, et EventTypeTransformer) (n *BaseNode)

NewBaseNode creates a new base node

func (*BaseNode) AddChild

func (n *BaseNode) AddChild(i Node)

AddChild implements the NodeParent interface

func (*BaseNode) AddClose added in v0.23.0

func (n *BaseNode) AddClose(fn astikit.CloseFunc)

func (*BaseNode) AddCloseWithError added in v0.23.0

func (n *BaseNode) AddCloseWithError(fn astikit.CloseFuncWithError)

func (*BaseNode) AddParent

func (n *BaseNode) AddParent(i Node)

AddParent implements the NodeChild interface

func (*BaseNode) AddStats added in v0.12.0

func (n *BaseNode) AddStats(ss ...astikit.StatOptions)

AddStats adds stats

func (*BaseNode) ChildIsStarted

func (n *BaseNode) ChildIsStarted(m NodeMetadata)

ChildIsStarted implements the NodeParent interface

func (*BaseNode) ChildIsStopped

func (n *BaseNode) ChildIsStopped(m NodeMetadata)

ChildIsStopped implements the NodeParent interface

func (*BaseNode) Children

func (n *BaseNode) Children() (ns []Node)

Children implements the NodeParent interface

func (*BaseNode) Close added in v0.19.0

func (n *BaseNode) Close() error

func (*BaseNode) Context

func (n *BaseNode) Context() context.Context

Context returns the node context

func (*BaseNode) Continue

func (n *BaseNode) Continue()

Continue implements the Starter interface

func (*BaseNode) DelChild

func (n *BaseNode) DelChild(i Node)

DelChild implements the NodeParent interface

func (*BaseNode) DelParent

func (n *BaseNode) DelParent(i Node)

DelParent implements the NodeChild interface

func (*BaseNode) DoWhenUnclosed added in v0.19.0

func (n *BaseNode) DoWhenUnclosed(fn func())

func (*BaseNode) HandlePause

func (n *BaseNode) HandlePause()

HandlePause handles the pause

func (*BaseNode) IsClosed added in v0.19.0

func (n *BaseNode) IsClosed() bool

func (*BaseNode) Metadata

func (n *BaseNode) Metadata() NodeMetadata

Metadata implements the Node interface

func (*BaseNode) ParentIsStarted

func (n *BaseNode) ParentIsStarted(m NodeMetadata)

ParentIsStarted implements the NodeChild interface

func (*BaseNode) ParentIsStopped

func (n *BaseNode) ParentIsStopped(m NodeMetadata)

ParentIsStopped implements the NodeChild interface

func (*BaseNode) Parents

func (n *BaseNode) Parents() (ns []Node)

Parents implements the NodeChild interface

func (*BaseNode) Pause

func (n *BaseNode) Pause()

Pause implements the Starter interface

func (*BaseNode) Start

func (n *BaseNode) Start(ctx context.Context, tc CreateTaskFunc, execFunc BaseNodeExecFunc)

Start starts the node

func (*BaseNode) Status

func (n *BaseNode) Status() string

Status implements the Starter interface

func (*BaseNode) Stop

func (n *BaseNode) Stop()

Stop stops the node

type BaseNodeExecFunc

type BaseNodeExecFunc func(t *astikit.Task)

BaseNodeExecFunc represents a node exec func

type BaseNodeStartFunc

type BaseNodeStartFunc func()

BaseNodeStartFunc represents a node start func

type Closer added in v0.19.0

type Closer interface {
	AddClose(astikit.CloseFunc)
	AddCloseWithError(astikit.CloseFuncWithError)
	Close() error
	DoWhenUnclosed(func())
	IsClosed() bool
}

type CreateTaskFunc

type CreateTaskFunc func() *astikit.Task

CreateTaskFunc is a method that can create a task

type Event

type Event struct {
	Name    EventName
	Payload interface{}
	Target  interface{}
}

Event is an event coming out of the encoder

func EventError

func EventError(target interface{}, err error) Event

EventError returns an error event

type EventCallback

type EventCallback func(e Event) (deleteListener bool)

EventCallback represents an event callback

type EventHandler

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

EventHandler represents an event handler

func NewEventHandler

func NewEventHandler() *EventHandler

NewEventHandler creates a new event handler

func (*EventHandler) Add

func (h *EventHandler) Add(target interface{}, eventName EventName, c EventCallback)

Add adds a new callback for a specific target and event name

func (*EventHandler) AddForAll

func (h *EventHandler) AddForAll(c EventCallback)

AddForAll adds a new callback for all events

func (*EventHandler) AddForEventName

func (h *EventHandler) AddForEventName(eventName EventName, c EventCallback)

AddForEventName adds a new callback for a specific event name

func (*EventHandler) AddForTarget

func (h *EventHandler) AddForTarget(target interface{}, c EventCallback)

AddForTarget adds a new callback for a specific target

func (*EventHandler) Emit

func (h *EventHandler) Emit(e Event)

Emit emits an event

func (*EventHandler) Log added in v0.26.0

type EventHandlerLogAdapter added in v0.33.1

type EventHandlerLogAdapter func(*EventHandler, *EventLogger)

func MessageMergingEventHandlerLogAdapter added in v0.33.1

func MessageMergingEventHandlerLogAdapter(period time.Duration) EventHandlerLogAdapter

type EventHandlerLogOptions added in v0.33.1

type EventHandlerLogOptions struct {
	Adapters     []EventHandlerLogAdapter
	Logger       astikit.StdLogger
	LoggerLevels map[EventName]astikit.LoggerLevel
}

type EventLogger added in v0.26.0

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

func (*EventLogger) Close added in v0.26.0

func (l *EventLogger) Close()

func (*EventLogger) Start added in v0.26.0

func (l *EventLogger) Start(ctx context.Context) *EventLogger

func (*EventLogger) Writef added in v0.33.0

func (l *EventLogger) Writef(ll astikit.LoggerLevel, format string, v ...interface{})

func (*EventLogger) Writek added in v0.33.0

func (l *EventLogger) Writek(ll astikit.LoggerLevel, key, msg string)

type EventName added in v0.33.1

type EventName string

func EventTypeToNodeEventName added in v0.12.0

func EventTypeToNodeEventName(eventType EventType) EventName

EventTypeToNodeEventName is the node EventTypeTransformer

func EventTypeToWorkflowEventName added in v0.12.0

func EventTypeToWorkflowEventName(eventType EventType) EventName

EventTypeToWorkflowEventName is the workflow EventTypeTransformer

type EventStat

type EventStat struct {
	Description string
	Label       string
	Name        string
	Target      interface{}
	Unit        string
	Value       interface{}
}

EventStat represents a stat event

type EventType added in v0.33.1

type EventType string

type EventTypeTransformer added in v0.12.0

type EventTypeTransformer func(eventType EventType) EventName

EventTypeTransformer represents a function capable of transforming an event type to an event name

type Node

Node represents a node

type NodeAutoStopOptions added in v0.35.0

type NodeAutoStopOptions struct {
	WhenAllChildrenAreStopped bool
	WhenAllParentsAreStopped  bool
}

type NodeChild

type NodeChild interface {
	NodeChildMapper
	ParentIsStarted(m NodeMetadata)
	ParentIsStopped(m NodeMetadata)
}

NodeChild represents an object with parent nodes

type NodeChildMapper

type NodeChildMapper interface {
	AddParent(n Node)
	DelParent(n Node)
	Parents() []Node
}

NodeChildMapper represents an object that can play with its parents map

type NodeDescriptor

type NodeDescriptor interface {
	Metadata() NodeMetadata
}

NodeDescriptor represents an object that can describe a node

type NodeMetadata

type NodeMetadata struct {
	Description string
	Label       string
	Name        string
	Tags        []string
}

NodeMetadata represents node metadata

func (NodeMetadata) Extend

func (m NodeMetadata) Extend(name, label, description string, tags ...string) NodeMetadata

Extend extends the node metadata

type NodeOptions

type NodeOptions struct {
	AutoStop *NodeAutoStopOptions
	Metadata NodeMetadata
}

NodeOptions represents node options

type NodeParent

type NodeParent interface {
	NodeParentMapper
	ChildIsStarted(m NodeMetadata)
	ChildIsStopped(m NodeMetadata)
}

NodeParent represents an object with child nodes

type NodeParentMapper

type NodeParentMapper interface {
	AddChild(n Node)
	Children() []Node
	DelChild(n Node)
}

NodeParentMapper represents an object that can play with its children map

type Server added in v0.9.0

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

func NewServer added in v0.9.0

func NewServer(o ServerOptions) *Server

func (*Server) EventHandlerAdapter added in v0.9.0

func (s *Server) EventHandlerAdapter(eh *EventHandler)

func (*Server) ServeWelcome added in v0.30.0

func (s *Server) ServeWelcome() http.Handler

func (*Server) SetWorkflow added in v0.9.0

func (s *Server) SetWorkflow(w *Workflow)

type ServerChildUpdate added in v0.28.0

type ServerChildUpdate struct {
	Child  string `json:"child"`
	Parent string `json:"parent"`
}

type ServerNode added in v0.9.0

type ServerNode struct {
	Children    []string `json:"children"`
	Closed      bool     `json:"closed"`
	Description string   `json:"description"`
	Label       string   `json:"label"`
	Name        string   `json:"name"`
	Parents     []string `json:"parents"`
	Status      string   `json:"status"`
	Tags        []string `json:"tags"`
}

type ServerNotifierFunc added in v0.30.0

type ServerNotifierFunc func(eventName EventName, payload interface{})

type ServerOptions added in v0.9.0

type ServerOptions struct {
	Logger       astikit.StdLogger
	NotifierFunc ServerNotifierFunc
}

type ServerStat added in v0.9.0

type ServerStat struct {
	Description string      `json:"description"`
	Label       string      `json:"label"`
	Name        string      `json:"name"`
	Target      string      `json:"target"`
	Unit        string      `json:"unit"`
	Value       interface{} `json:"value"`
}

type ServerWelcome added in v0.9.0

type ServerWelcome struct {
	Workflow *ServerWorkflow `json:"workflow,omitempty"`
}

type ServerWorkflow added in v0.9.0

type ServerWorkflow struct {
	Name   string       `json:"name"`
	Nodes  []ServerNode `json:"nodes"`
	Status string       `json:"status"`
}

type Starter

type Starter interface {
	Continue()
	Pause()
	Start(ctx context.Context, t CreateTaskFunc)
	Status() string
	Stop()
}

Starter represents an object that can start/pause/continue/stop

type StatValueHostUsage added in v0.34.0

type StatValueHostUsage struct {
	CPU    StatValueHostUsageCPU    `json:"cpu"`
	Memory StatValueHostUsageMemory `json:"memory"`
}

type StatValueHostUsageCPU added in v0.34.0

type StatValueHostUsageCPU struct {
	Individual []float64 `json:"individual"`
	Process    float64   `json:"process"`
	Total      float64   `json:"total"`
}

type StatValueHostUsageMemory added in v0.34.0

type StatValueHostUsageMemory struct {
	Resident uint64 `json:"resident"`
	Total    uint64 `json:"total"`
	Used     uint64 `json:"used"`
	Virtual  uint64 `json:"virtual"`
}

type Stater

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

Stater represents an object that can compute and handle stats

func NewStater added in v0.12.0

func NewStater(period time.Duration, eh *EventHandler) (s *Stater)

NewStater creates a new stater

func (*Stater) AddStats added in v0.12.0

func (s *Stater) AddStats(target interface{}, os ...astikit.StatOptions)

AddStats adds stats

func (*Stater) DelStats added in v0.12.0

func (s *Stater) DelStats(target interface{}, os ...astikit.StatOptions)

DelStats deletes stats

func (*Stater) Start added in v0.12.0

func (s *Stater) Start(ctx context.Context)

Start starts the stater

func (*Stater) Stop added in v0.12.0

func (s *Stater) Stop()

Stop stops the stater

type Workflow

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

Workflow represents a workflow

func NewWorkflow

func NewWorkflow(ctx context.Context, name string, eh *EventHandler, tf CreateTaskFunc, c *astikit.Closer, s *Stater) (w *Workflow)

NewWorkflow creates a new workflow

func (*Workflow) AddChild

func (w *Workflow) AddChild(n Node)

AddChild adds a child to the workflow

func (*Workflow) AddDefaultStats added in v0.31.0

func (w *Workflow) AddDefaultStats() (err error)

func (*Workflow) Children

func (w *Workflow) Children() []Node

Children returns the workflow children

func (*Workflow) Continue

func (w *Workflow) Continue()

Continue continues the workflow

func (*Workflow) DelChild

func (w *Workflow) DelChild(n Node)

DelChild deletes a child from the workflow

func (*Workflow) Name

func (w *Workflow) Name() string

Name returns the workflow name

func (*Workflow) NewRecording added in v0.9.0

func (w *Workflow) NewRecording(o WorkflowRecordingOptions) (r *WorkflowRecording)

func (*Workflow) Pause

func (w *Workflow) Pause()

Pause pauses the workflow

func (*Workflow) Start

func (w *Workflow) Start()

Start starts the workflow

func (*Workflow) StartNodes

func (w *Workflow) StartNodes(ns ...Node)

StartNodes starts nodes

func (*Workflow) StartNodesInSubTask

func (w *Workflow) StartNodesInSubTask(ns ...Node) (t *astikit.Task)

StartNodesInSubTask starts nodes in a new sub task

func (*Workflow) StartWithOptions

func (w *Workflow) StartWithOptions(o WorkflowStartOptions)

StartWithOptions starts the workflow with options

func (*Workflow) Status

func (w *Workflow) Status() string

Status returns the workflow status

func (*Workflow) Stop

func (w *Workflow) Stop()

Stop stops the workflow

type WorkflowRecording added in v0.9.0

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

func (*WorkflowRecording) Start added in v0.9.0

func (r *WorkflowRecording) Start(ctx context.Context) (err error)

func (*WorkflowRecording) Stop added in v0.9.0

func (r *WorkflowRecording) Stop()

type WorkflowRecordingOptions added in v0.9.0

type WorkflowRecordingOptions struct {
	Dst    string
	Logger astikit.StdLogger
}

type WorkflowStartGroup

type WorkflowStartGroup struct {
	Callback func(t *astikit.Task)
	Nodes    []Node
}

WorkflowStartGroup represents a workflow start group

type WorkflowStartOptions

type WorkflowStartOptions struct {
	Groups []WorkflowStartGroup
}

WorkflowStartOptions represents workflow start options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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