45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package workspacelifecycle
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"inbox/internal/app/workspaceprovision"
|
|
"inbox/internal/app/workspaceruntime"
|
|
"inbox/internal/domain/workspace"
|
|
)
|
|
|
|
type Provisioner interface {
|
|
Provision(ctx context.Context, req workspaceprovision.ProvisionRequest) (workspace.Workspace, workspaceruntime.Runtime, error)
|
|
}
|
|
|
|
type RuntimeManager interface {
|
|
Ensure(ctx context.Context, workspaceID string) (workspace.Workspace, workspaceruntime.Runtime, error)
|
|
}
|
|
|
|
type Service struct {
|
|
provision Provisioner
|
|
runtime RuntimeManager
|
|
}
|
|
|
|
func NewService(provision Provisioner, runtime RuntimeManager) *Service {
|
|
return &Service{
|
|
provision: provision,
|
|
runtime: runtime,
|
|
}
|
|
}
|
|
|
|
func (s *Service) Provision(ctx context.Context, req workspaceprovision.ProvisionRequest) (workspace.Workspace, workspaceruntime.Runtime, error) {
|
|
if s.provision == nil {
|
|
return workspace.Workspace{}, workspaceruntime.Runtime{}, fmt.Errorf("workspace provisioning is not configured")
|
|
}
|
|
return s.provision.Provision(ctx, req)
|
|
}
|
|
|
|
func (s *Service) Ensure(ctx context.Context, workspaceID string) (workspace.Workspace, workspaceruntime.Runtime, error) {
|
|
if s.runtime == nil {
|
|
return workspace.Workspace{}, workspaceruntime.Runtime{}, fmt.Errorf("workspace runtime is not configured")
|
|
}
|
|
return s.runtime.Ensure(ctx, workspaceID)
|
|
}
|