This repository has been archived on 2026-07-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
codespace/internal/service/process_service.go
T
2026-07-02 15:07:54 +08:00

49 lines
1.4 KiB
Go

package service
import (
"codespace/internal/process"
"codespace/internal/workspace"
)
// ProcessService manages OpenCode processes for workspaces.
type ProcessService struct {
workspaces workspace.Manager
processes process.Manager
}
// NewProcessService creates a ProcessService.
func NewProcessService(workspaces workspace.Manager, processes process.Manager) *ProcessService {
return &ProcessService{workspaces: workspaces, processes: processes}
}
// Start starts an OpenCode process for the given workspace.
func (s *ProcessService) Start(workspaceID string) error {
ws, err := s.workspaces.Get(workspaceID)
if err != nil {
return err
}
return s.processes.Start(workspaceID, ws.Root)
}
// Stop stops the OpenCode process for the given workspace.
func (s *ProcessService) Stop(workspaceID string) error {
return s.processes.Stop(workspaceID)
}
// Restart restarts the OpenCode process for the given workspace.
func (s *ProcessService) Restart(workspaceID string) error {
ws, err := s.workspaces.Get(workspaceID)
if err != nil {
return err
}
return s.processes.Restart(workspaceID, ws.Root)
}
// Status returns the process status for the given workspace.
func (s *ProcessService) Status(workspaceID string) (process.Status, error) {
if _, err := s.workspaces.Get(workspaceID); err != nil {
return process.Status{}, err
}
return s.processes.Status(workspaceID), nil
}