sbxstore

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusCreating = "creating"
	StatusRunning  = "running"
	StatusPausing  = "pausing"
	StatusPaused   = "paused"
	StatusResuming = "resuming"
	StatusDeleting = "deleting"
	StatusOffline  = "offline"
)

Status constants for sandbox lifecycle.

Variables

This section is empty.

Functions

func ValidTransition

func ValidTransition(from, to string) bool

ValidTransition checks whether a status transition is allowed.

Types

type IdleWatcher

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

IdleWatcher monitors sandboxes and auto-pauses idle ones.

func NewIdleWatcher

func NewIdleWatcher(database *db.DB, procMgr process.Manager, store *Store, getTimeout func() time.Duration) *IdleWatcher

NewIdleWatcher creates a new idle sandbox watcher. The getTimeout function is called each check cycle to resolve the current idle timeout. If it returns 0, idle checking is skipped (disabled).

func (*IdleWatcher) Start

func (w *IdleWatcher) Start()

Start begins the idle check loop. Call Stop() to terminate.

func (*IdleWatcher) Stop

func (w *IdleWatcher) Stop()

Stop terminates the idle watcher.

type Sandbox

type Sandbox struct {
	ID              string     `json:"id"`
	ShortID         string     `json:"short_id,omitempty"`
	WorkspaceID     string     `json:"workspace_id"`
	Name            string     `json:"name"`
	Type            string     `json:"type"`
	Status          string     `json:"status"`
	SandboxName     string     `json:"sandbox_name,omitempty"`
	PodIP           string     `json:"pod_ip,omitempty"`
	ProxyToken      string     `json:"-"`
	OpencodeToken   string     `json:"-"`
	OpenclawToken   string     `json:"-"`
	TunnelToken     string     `json:"-"`
	CreatedAt       time.Time  `json:"created_at"`
	LastActivityAt  *time.Time `json:"last_activity_at,omitempty"`
	PausedAt        *time.Time `json:"paused_at,omitempty"`
	IsLocal         bool       `json:"is_local"`
	LastHeartbeatAt *time.Time `json:"last_heartbeat_at,omitempty"`
	CPU             int        `json:"cpu,omitempty"`
	Memory          int64      `json:"memory,omitempty"`
	IdleTimeout     *int       `json:"idle_timeout,omitempty"`
}

Sandbox represents a sandbox with its current state.

type Store

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

Store manages sandboxes via PostgreSQL.

func NewStore

func NewStore(database *db.DB) *Store

func (*Store) Create

func (s *Store) Create(id, workspaceID, name, sandboxType, sandboxName, opencodeToken, proxyToken, openclawToken, shortID string, cpu int, memory int64, idleTimeout *int) (*Sandbox, error)

Create inserts a new sandbox into the DB with 'creating' status.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes a sandbox from the DB.

func (*Store) Get

func (s *Store) Get(id string) (*Sandbox, bool)

Get returns a sandbox from DB.

func (*Store) GetByShortID

func (s *Store) GetByShortID(shortID string) (*Sandbox, bool)

GetByShortID returns a sandbox looked up by its short ID.

func (*Store) ListByWorkspace

func (s *Store) ListByWorkspace(workspaceID string) []*Sandbox

ListByWorkspace returns all sandboxes for a workspace from the database.

func (*Store) Resolve

func (s *Store) Resolve(idOrShortID string) (*Sandbox, bool)

Resolve finds a sandbox by either short ID or UUID. UUIDs are 36 chars; short IDs are 16 chars or fewer. We use 20 as the threshold.

func (*Store) UpdateActivity

func (s *Store) UpdateActivity(id string)

UpdateActivity records user activity on a sandbox.

func (*Store) UpdateStatus

func (s *Store) UpdateStatus(id, status string) error

UpdateStatus transitions a sandbox to a new status.

Jump to

Keyboard shortcuts

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