Documentation
¶
Index ¶
- Constants
- func ValidTransition(from, to string) bool
- type IdleWatcher
- type Sandbox
- type Store
- func (s *Store) Create(...) (*Sandbox, error)
- func (s *Store) Delete(id string) error
- func (s *Store) Get(id string) (*Sandbox, bool)
- func (s *Store) GetByShortID(shortID string) (*Sandbox, bool)
- func (s *Store) ListByWorkspace(workspaceID string) []*Sandbox
- func (s *Store) Resolve(idOrShortID string) (*Sandbox, bool)
- func (s *Store) UpdateActivity(id string)
- func (s *Store) UpdateStatus(id, status string) error
Constants ¶
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 ¶
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.
type Sandbox ¶
type Sandbox struct {
ID string `json:"id"`
ShortID string `json:"shortId,omitempty"`
WorkspaceID string `json:"workspaceId"`
Name string `json:"name"`
Type string `json:"type"`
Status string `json:"status"`
SandboxName string `json:"sandboxName,omitempty"`
PodIP string `json:"podIp,omitempty"`
ProxyToken string `json:"-"`
OpencodeToken string `json:"-"`
OpenclawToken string `json:"-"`
TunnelToken string `json:"-"`
CreatedAt time.Time `json:"createdAt"`
LastActivityAt *time.Time `json:"lastActivityAt,omitempty"`
PausedAt *time.Time `json:"pausedAt,omitempty"`
IsLocal bool `json:"isLocal"`
LastHeartbeatAt *time.Time `json:"lastHeartbeatAt,omitempty"`
CPUMillicores int `json:"cpuMillicores,omitempty"`
MemoryBytes int64 `json:"memoryBytes,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 (*Store) Create ¶
func (s *Store) Create(id, workspaceID, name, sandboxType, sandboxName, opencodeToken, proxyToken, openclawToken, shortID string, cpuMillicores int, memoryBytes int64) (*Sandbox, error)
Create inserts a new sandbox into the DB with 'creating' status.
func (*Store) GetByShortID ¶
GetByShortID returns a sandbox looked up by its short ID.
func (*Store) ListByWorkspace ¶
ListByWorkspace returns all sandboxes for a workspace from the database.
func (*Store) Resolve ¶
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 ¶
UpdateActivity records user activity on a sandbox.
func (*Store) UpdateStatus ¶
UpdateStatus transitions a sandbox to a new status.