live

package
v0.0.0-...-01ca449 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	ID              string             `json:"id"`
	StrategyName    string             `json:"strategy_name"`
	StrategyPath    string             `json:"strategy_path"`
	FrameworkRoot   string             `json:"framework_root"`
	PID             int                `json:"pid"`
	Status          InstanceStatus     `json:"status"`
	StartedAt       time.Time          `json:"started_at"`
	LastStatusCheck time.Time          `json:"last_status_check"`
	Restarts        int                `json:"restarts"`
	Error           string             `json:"error"`
	Context         context.Context    `json:"-"`
	Cancel          context.CancelFunc `json:"-"`
	Cmd             *exec.Cmd          `json:"-"`
}

Instance represents a running strategy instance

type InstanceManager

type InstanceManager interface {
	// Start spawns a new strategy instance
	Start(ctx context.Context, strategy *config.Strategy, frameworkRoot string) (*Instance, error)

	// Stop gracefully terminates an instance by ID
	Stop(instanceID string) error

	// StopByStrategyName gracefully terminates an instance by strategy name
	StopByStrategyName(strategyName string) error

	// Kill forcefully terminates an instance
	Kill(instanceID string) error

	// Get retrieves a specific instance
	Get(instanceID string) (*Instance, error)

	// List returns all instances (filtered by status)
	List(status InstanceStatus) ([]*Instance, error)

	// LoadRunning loads instances from state file (after restart)
	LoadRunning(ctx context.Context) error

	// SaveState persists current state to disk
	SaveState() error

	// Shutdown gracefully terminates all instances
	Shutdown(ctx context.Context, timeout time.Duration) error
}

InstanceManager orchestrates spawning, tracking, and lifecycle of strategy instances

type InstanceStatus

type InstanceStatus string

InstanceStatus represents the current state of a strategy instance

const (
	StatusRunning    InstanceStatus = "running"
	StatusStopped    InstanceStatus = "stopped"
	StatusCrashed    InstanceStatus = "crashed"
	StatusRestarting InstanceStatus = "restarting"
)

type ProcessSpawner

type ProcessSpawner interface {
	// Spawn creates a new kronos run-strategy process
	Spawn(ctx context.Context, strategy *config.Strategy) (*exec.Cmd, error)

	// AttachMonitor starts monitoring process for crashes
	AttachMonitor(instance *Instance) error
}

ProcessSpawner creates and configures child processes with proper isolation

type Runtime

type Runtime interface {
	Run(strategyDir string) error
}

Runtime is the interface for the live trading startup

type SignalHandler

type SignalHandler interface {
	// Handle registers signal handlers
	Handle(ctx context.Context, onSignal func(os.Signal) error) error
}

SignalHandler handles OS signals and coordinates graceful shutdown

type StateStore

type StateStore interface {
	// Load reads persisted state from disk
	Load() ([]*Instance, error)

	// Save writes current state to disk
	Save(instances []*Instance) error

	// GetPath returns the path to the state file
	GetPath() string
}

StateStore persists and recovers instance state across CLI invocations

Jump to

Keyboard shortcuts

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