Major refactoring to hexagonal (ports & adapters) architecture: - Add service layer (apikey_service, project_service) for business logic - Add webhook system with dispatcher and delivery tracking - Add command queue with priority-based processing - Add rate limiting with sliding window algorithm - Add audit logging for command execution - Add OpenTelemetry integration (traces, metrics, spans) - Add circuit breaker for fault tolerance - Add cached repository wrapper for performance - Add comprehensive validation package - Add Kubernetes client integration for pod management - Add database migrations (allowed_ips, audit_log, rate_limiting, queue, webhooks) - Add network policy and PodDisruptionBudget for k8s - Remove legacy executor and projects/registry packages - Untrack secrets.yaml (now managed via envault) - Add coverage.out to .gitignore - Add e2e test infrastructure with docker-compose - Add comprehensive documentation (API, architecture, operations, plans) - Add golangci-lint config and pre-commit hook Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
80 lines
2.6 KiB
Go
80 lines
2.6 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
// QueuedCommandID is a strongly-typed identifier for queued commands.
|
|
type QueuedCommandID string
|
|
|
|
// QueueStatus represents the status of a queued command.
|
|
type QueueStatus string
|
|
|
|
// Available queue statuses.
|
|
const (
|
|
QueueStatusPending QueueStatus = "pending"
|
|
QueueStatusRunning QueueStatus = "running"
|
|
QueueStatusCompleted QueueStatus = "completed"
|
|
QueueStatusFailed QueueStatus = "failed"
|
|
QueueStatusCancelled QueueStatus = "cancelled"
|
|
)
|
|
|
|
// IsTerminal returns true if the status represents a final state.
|
|
func (s QueueStatus) IsTerminal() bool {
|
|
return s == QueueStatusCompleted || s == QueueStatusFailed || s == QueueStatusCancelled
|
|
}
|
|
|
|
// String returns the status as a string.
|
|
func (s QueueStatus) String() string {
|
|
return string(s)
|
|
}
|
|
|
|
// QueuedCommand represents a command waiting to be executed.
|
|
type QueuedCommand struct {
|
|
ID QueuedCommandID `json:"id"`
|
|
ProjectID string `json:"project_id"`
|
|
Command string `json:"command"` // Prompt for claude, command for shell, JSON-encoded args for git
|
|
CommandType CommandType `json:"command_type"` // claude, shell, git
|
|
WorkingDir string `json:"working_dir,omitempty"`
|
|
Status QueueStatus `json:"status"`
|
|
Priority int `json:"priority"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
StartedAt *time.Time `json:"started_at,omitempty"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
ExitCode *int `json:"exit_code,omitempty"`
|
|
Output string `json:"output,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
APIKeyID string `json:"api_key_id,omitempty"` // For audit trail
|
|
}
|
|
|
|
// CommandResult holds the result of executing a queued command.
|
|
type QueuedCommandResult struct {
|
|
ExitCode int
|
|
Output string
|
|
Error string
|
|
}
|
|
|
|
// QueueFilters contains filter options for listing queued commands.
|
|
type QueueFilters struct {
|
|
Status *QueueStatus // Filter by status
|
|
Limit int // Max results (default 100)
|
|
Offset int // For pagination
|
|
SortOrder string // "asc" or "desc" by created_at (default "desc")
|
|
}
|
|
|
|
// DefaultQueueFilters returns sensible defaults for queue listing.
|
|
func DefaultQueueFilters() *QueueFilters {
|
|
return &QueueFilters{
|
|
Limit: 100,
|
|
Offset: 0,
|
|
SortOrder: "desc",
|
|
}
|
|
}
|
|
|
|
// QueueStats holds statistics about the command queue.
|
|
type QueueStats struct {
|
|
TotalPending int `json:"total_pending"`
|
|
TotalRunning int `json:"total_running"`
|
|
TotalCompleted int `json:"total_completed"`
|
|
TotalFailed int `json:"total_failed"`
|
|
TotalCancelled int `json:"total_cancelled"`
|
|
}
|