task

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DockerRuntimeTcpListenPortBase = 8100
)
View Source
const (
	SPEARDockerReadBufferSize = 4 * 1024 * 1024
)

Variables

View Source
var (
	DockerRuntimeTcpListenPort = ""
)

Functions

func InitTaskRuntimes

func InitTaskRuntimes(cfg *TaskRuntimeConfig)

initialize task runtimes

func RegisterSupportedTaskType

func RegisterSupportedTaskType(taskType TaskType)

register task runtime

func StopTaskRuntimes

func StopTaskRuntimes()

func UnregisterSupportedTaskType

func UnregisterSupportedTaskType(taskType TaskType)

unregister task runtime

Types

type DockerTask

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

func (*DockerTask) CommChannels

func (p *DockerTask) CommChannels() (chan Message, chan Message, error)

func (*DockerTask) GetResult

func (p *DockerTask) GetResult() *error

func (*DockerTask) GetVar

func (p *DockerTask) GetVar(key TaskVar) (interface{}, bool)

func (*DockerTask) ID

func (p *DockerTask) ID() TaskID

func (*DockerTask) Name

func (p *DockerTask) Name() string

func (*DockerTask) NextRequestID

func (p *DockerTask) NextRequestID() uint64

func (*DockerTask) SetVar

func (p *DockerTask) SetVar(key TaskVar, value interface{})

func (*DockerTask) Start

func (p *DockerTask) Start() error

func (*DockerTask) Status

func (p *DockerTask) Status() TaskStatus

func (*DockerTask) Stop

func (p *DockerTask) Stop() error

func (*DockerTask) Wait

func (p *DockerTask) Wait() (int, error)

type DockerTaskRuntime

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

func NewDockerTaskRuntime

func NewDockerTaskRuntime(rtCfg *TaskRuntimeConfig) (*DockerTaskRuntime, error)

func (*DockerTaskRuntime) CreateTask

func (d *DockerTaskRuntime) CreateTask(cfg *TaskConfig) (Task, error)

func (*DockerTaskRuntime) Start

func (d *DockerTaskRuntime) Start() error

func (*DockerTaskRuntime) Stop

func (d *DockerTaskRuntime) Stop() error

type DylibTaskRuntime

type DylibTaskRuntime struct {
}

implement TaskRuntimeDylib

func (*DylibTaskRuntime) CreateTask

func (d *DylibTaskRuntime) CreateTask(cfg *TaskConfig) (Task, error)

func (*DylibTaskRuntime) Start

func (d *DylibTaskRuntime) Start() error

func (*DylibTaskRuntime) Stop

func (d *DylibTaskRuntime) Stop() error

type Message

type Message []byte

message type []bytes

type ProcessTask

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

func NewProcessTask

func NewProcessTask(cfg *TaskConfig) *ProcessTask

func (*ProcessTask) CommChannels

func (p *ProcessTask) CommChannels() (chan Message, chan Message, error)

func (*ProcessTask) GetResult

func (p *ProcessTask) GetResult() *error

func (*ProcessTask) GetVar

func (p *ProcessTask) GetVar(key TaskVar) (interface{}, bool)

func (*ProcessTask) ID

func (p *ProcessTask) ID() TaskID

func (*ProcessTask) Name

func (p *ProcessTask) Name() string

func (*ProcessTask) NextRequestID

func (p *ProcessTask) NextRequestID() uint64

func (*ProcessTask) SetVar

func (p *ProcessTask) SetVar(key TaskVar, value interface{})

func (*ProcessTask) Start

func (p *ProcessTask) Start() error

func (*ProcessTask) Status

func (p *ProcessTask) Status() TaskStatus

func (*ProcessTask) Stop

func (p *ProcessTask) Stop() error

func (*ProcessTask) Wait

func (p *ProcessTask) Wait() (int, error)

type ProcessTaskRuntime

type ProcessTaskRuntime struct {
}

implement TaskRuntimeProcess

func NewProcessTaskRuntime

func NewProcessTaskRuntime() *ProcessTaskRuntime

func (*ProcessTaskRuntime) CreateTask

func (p *ProcessTaskRuntime) CreateTask(cfg *TaskConfig) (Task, error)

func (*ProcessTaskRuntime) Start

func (p *ProcessTaskRuntime) Start() error

func (*ProcessTaskRuntime) Stop

func (p *ProcessTaskRuntime) Stop() error

type Task

type Task interface {
	ID() TaskID
	// start task
	Start() error
	// stop task
	Stop() error
	// get task name
	Name() string
	// get task status
	Status() TaskStatus
	// get task result
	GetResult() *error
	// get communication channel
	CommChannels() (chan Message, chan Message, error)
	// wait for task to finish
	Wait() (int, error)
	// next request id
	NextRequestID() uint64
	// set task variable
	SetVar(key TaskVar, value interface{})
	// get task variable
	GetVar(key TaskVar) (interface{}, bool)
}

type TaskConfig

type TaskConfig struct {
	// task name
	Name     string
	Image    string
	Cmd      string
	Args     []string
	HostAddr string
}

type TaskID

type TaskID string

type TaskRuntime

type TaskRuntime interface {
	// create task
	CreateTask(cfg *TaskConfig) (Task, error)
	Start() error
	Stop() error
}

interface for taskruntime

func GetTaskRuntime

func GetTaskRuntime(taskType TaskType) (TaskRuntime, error)

factory method for TaskRuntime

type TaskRuntimeConfig

type TaskRuntimeConfig struct {
	Debug         bool
	Cleanup       bool
	StartServices bool
}

type TaskStatus

type TaskStatus int

task status enum

const (
	TaskStatusRunning TaskStatus = iota
	TaskStatusInit
	TaskStatusStopped
)

type TaskType

type TaskType int

task type enum

const (
	TaskTypeUnknown TaskType = iota
	TaskTypeDocker           // 1
	TaskTypeProcess          // 2
	TaskTypeDylib            // 3
	TaskTypeWasm             // 4
)

type TaskVar

type TaskVar int
const (
	TVTest TaskVar = iota
	TVOpenAIBaseURL
	TVOpenAIAPIKey
)

type WasmTaskRuntime

type WasmTaskRuntime struct {
}

implement TaskRuntimeWasm

func (*WasmTaskRuntime) CreateTask

func (w *WasmTaskRuntime) CreateTask(cfg *TaskConfig) (Task, error)

func (*WasmTaskRuntime) Start

func (w *WasmTaskRuntime) Start() error

func (*WasmTaskRuntime) Stop

func (w *WasmTaskRuntime) Stop() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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