Documentation
¶
Index ¶
- Variables
- func DockerImageDownloadJobInit(ctx context.Context, job *jobs.JobObj) (jobs.JobWorker, errorx.Error)
- func DockerImageDownloadJobWorker(ctx context.Context, worker jobs.JobWorker, progress chan<- float32) error
- func RegisterDockerImageJob()
- func RegisterExecutor(name string, factory func() CodeExecutorIface)
- func ScheduleDockerImageDownloadJob(ctx context.Context, executorName string) (*jobs.JobObj, error)
- type CodeExecutionResult
- type CodeExecutorCommonConfig
- type CodeExecutorIface
- type ConfigCodeExecutorDocker
- type ConfigCodeExecutorLocal
- type ConfigCodeExecutorSSH
- type ConfigCodeExecutors
- type DockerExecutor
- func (e *DockerExecutor) ExecutePythonCode(ctx context.Context, contextJob *jobs.JobObj, code string) (*CodeExecutionResult, error)
- func (e *DockerExecutor) GetExecutorId() string
- func (e *DockerExecutor) Init() error
- func (e *DockerExecutor) InstallRuntime(ctx context.Context, contextJob *jobs.JobObj) error
- type DockerImageDownloadJobParams
- type ExecutorType
- type LocalExecutor
- func (e *LocalExecutor) ExecutePythonCode(ctx context.Context, contextJob *jobs.JobObj, code string) (*CodeExecutionResult, error)
- func (e *LocalExecutor) GetExecutorId() string
- func (e *LocalExecutor) Init() error
- func (e *LocalExecutor) InstallRuntime(ctx context.Context, contextJob *jobs.JobObj) error
- type SSHExecutor
Constants ¶
This section is empty.
Variables ¶
var LoggerConfigKey = "code_executor"
Functions ¶
func DockerImageDownloadJobInit ¶
func DockerImageDownloadJobInit(ctx context.Context, job *jobs.JobObj) (jobs.JobWorker, errorx.Error)
DockerImageDownloadJobInit initializes the Docker image download job
func DockerImageDownloadJobWorker ¶
func DockerImageDownloadJobWorker(ctx context.Context, worker jobs.JobWorker, progress chan<- float32) error
DockerImageDownloadJobWorker performs work for Docker image download jobs
func RegisterDockerImageJob ¶
func RegisterDockerImageJob()
RegisterDockerImageJob registers the Docker image download job type
func RegisterExecutor ¶
func RegisterExecutor(name string, factory func() CodeExecutorIface)
Types ¶
type CodeExecutionResult ¶
type CodeExecutionResult struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key"`
ExecutorType ExecutorType `json:"executor_type" gorm:"not null"`
ExecutorId string `json:"executor_id" gorm:"not null"`
RuntimeId string `json:"runtime_id" gorm:"not null"`
Name string `json:"name" gorm:"not null"`
ConfigId uuid.UUID `json:"config_id" gorm:"type:uuid;not null"`
ConfigPtr interface{} `json:"-" gorm:"-"`
Completed bool `json:"completed" default:"false"`
Success bool `json:"success" default:"false"`
ExitCode int `json:"exit_code" default:"0"`
Stdout string `json:"stdout" default:""`
Stderr string `json:"stderr" default:""`
Hostname string `json:"hostname"`
StartTimeMs int64 `json:"start_time" gorm:"index" doc:"unix timestamp in milliseconds"`
EndTimeMs int64 `json:"end_time" gorm:"index" doc:"unix timestamp in milliseconds"`
DurationSec float64 `json:"duration_sec"`
Error string `json:"error,omitempty"`
}
type CodeExecutorIface ¶
type CodeExecutorIface interface {
Init() error
InstallRuntime(ctx context.Context, contextJob *jobs.JobObj) error
ExecutePythonCode(ctx context.Context, contextJob *jobs.JobObj, code string) (*CodeExecutionResult, error)
GetExecutorId() string
}
func GetCodeExecutor ¶
func NewCodeExecutor ¶
type ConfigCodeExecutorDocker ¶
type ConfigCodeExecutorDocker struct {
CodeExecutorCommonConfig `mapstructure:",squash"` // squash the common config into the docker config
Image string `mapstructure:"image"`
MemLimitMB float64 `mapstructure:"mem_limit_mb" default:"256"`
CPUsLimit float64 `mapstructure:"cpus_limit_cores" default:"1"`
PIDsLimit int64 `mapstructure:"pids_limit" default:"50"`
}
func (*ConfigCodeExecutorDocker) ExecutorConfigEqual ¶
func (c *ConfigCodeExecutorDocker) ExecutorConfigEqual(other *ConfigCodeExecutorDocker) bool
type ConfigCodeExecutorLocal ¶
type ConfigCodeExecutorLocal struct {
CodeExecutorCommonConfig `mapstructure:",squash"` // squash the common config into the local config
}
func (*ConfigCodeExecutorLocal) ExecutorConfigEqual ¶
func (c *ConfigCodeExecutorLocal) ExecutorConfigEqual(other *ConfigCodeExecutorLocal) bool
type ConfigCodeExecutorSSH ¶
type ConfigCodeExecutorSSH struct {
CodeExecutorCommonConfig `mapstructure:",squash"` // squash the common config into the ssh config
Host string `mapstructure:"host" yaml:"host,omitempty"`
Port int `mapstructure:"port" yaml:"port,omitempty" default:"22"`
Username string `mapstructure:"username" yaml:"username,omitempty"`
Password string `mapstructure:"password" yaml:"password,omitempty"`
PrivateKey string `mapstructure:"private_key" yaml:"private_key,omitempty"`
}
func (*ConfigCodeExecutorSSH) ExecutorConfigEqual ¶
func (c *ConfigCodeExecutorSSH) ExecutorConfigEqual(other *ConfigCodeExecutorSSH) bool
type ConfigCodeExecutors ¶
type ConfigCodeExecutors struct {
Docker map[string]*ConfigCodeExecutorDocker `mapstructure:"docker"`
SSH map[string]*ConfigCodeExecutorSSH `mapstructure:"ssh"`
Local map[string]*ConfigCodeExecutorLocal `mapstructure:"local"`
}
func (*ConfigCodeExecutors) GetDefault ¶
func (c *ConfigCodeExecutors) GetDefault() interface{}
Add these methods to ConfigCodeExecutors to implement ConfigComponent
type DockerExecutor ¶
type DockerExecutor struct {
DockerExecutorID uuid.UUID `json:"docker_executor_id" gorm:"type:uuid;primary_key"`
CodeExecutor CodeExecutionResult `gorm:"foreignKey:DockerExecutorID"`
Image string `json:"image" gorm:"not null"`
// contains filtered or unexported fields
}
DockerExecutor extends CodeExecutor with Docker-specific functionality
func (*DockerExecutor) ExecutePythonCode ¶
func (e *DockerExecutor) ExecutePythonCode(ctx context.Context, contextJob *jobs.JobObj, code string) (*CodeExecutionResult, error)
ExecutePythonCode builds and runs the Docker container executing the Python code
func (*DockerExecutor) GetExecutorId ¶
func (e *DockerExecutor) GetExecutorId() string
GetExecutorId returns the Docker container id
func (*DockerExecutor) Init ¶
func (e *DockerExecutor) Init() error
func (*DockerExecutor) InstallRuntime ¶
type DockerImageDownloadJobParams ¶
type DockerImageDownloadJobParams struct {
TenantID uuid.UUID `json:"tenant_id"`
CodeExecutor string `json:"code_executor"`
CodeExecutorPtr *DockerExecutor `json:"-" gorm:"-"`
}
DockerImageDownloadJobParams represents parameters for Docker image download jobs
type ExecutorType ¶
type ExecutorType string
const ( ExecutorTypeDocker ExecutorType = "docker" ExecutorTypeSSH ExecutorType = "ssh" ExecutorTypeLocal ExecutorType = "localhost" )
type LocalExecutor ¶
type LocalExecutor struct {
DockerExecutorID uuid.UUID `json:"docker_executor_id" gorm:"type:uuid;primary_key"`
CodeExecutor CodeExecutionResult `gorm:"foreignKey:DockerExecutorID"`
// contains filtered or unexported fields
}
LocalExecutor implements CodeExecutor for local execution.
func (*LocalExecutor) ExecutePythonCode ¶
func (e *LocalExecutor) ExecutePythonCode(ctx context.Context, contextJob *jobs.JobObj, code string) (*CodeExecutionResult, error)
ExecutePythonCode writes the code to a temporary directory and executes it.
func (*LocalExecutor) GetExecutorId ¶
func (e *LocalExecutor) GetExecutorId() string
GetExecutorId returns an empty string as localhost doesn't have an executor id.
func (*LocalExecutor) InstallRuntime ¶
type SSHExecutor ¶
type SSHExecutor struct {
DockerExecutorID uuid.UUID `json:"docker_executor_id" gorm:"type:uuid;primary_key"`
CodeExecutor CodeExecutionResult `gorm:"foreignKey:DockerExecutorID"`
// contains filtered or unexported fields
}
SSHExecutor implements CodeExecutor for remote SSH execution (stubbed).
func (*SSHExecutor) ExecutePythonCode ¶
func (e *SSHExecutor) ExecutePythonCode(ctx context.Context, contextJob *jobs.JobObj, code string) (*CodeExecutionResult, error)
ExecutePythonCode simulates executing Python code via SSH.
func (*SSHExecutor) GetExecutorId ¶
func (e *SSHExecutor) GetExecutorId() string
GetExecutorId returns the SSH executor id.
func (*SSHExecutor) Init ¶
func (e *SSHExecutor) Init() error
Init sets the timeout for SSH execution.