rdev/internal/port/command_queue.go
jordan 72d16929ca feat: Implement hexagonal architecture with services, webhooks, queue, and telemetry
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>
2026-01-25 19:57:46 -07:00

39 lines
1.6 KiB
Go

package port
import (
"context"
"github.com/orchard9/rdev/internal/domain"
)
// CommandQueue defines operations for the command queue repository.
type CommandQueue interface {
// Enqueue adds a command to the queue.
Enqueue(ctx context.Context, cmd *domain.QueuedCommand) error
// Dequeue retrieves and locks the next pending command for a project.
// Returns nil if no commands are pending.
// The command status is atomically updated to 'running'.
Dequeue(ctx context.Context, projectID string) (*domain.QueuedCommand, error)
// UpdateStatus updates the status of a queued command.
// If result is provided, it also updates the result fields.
UpdateStatus(ctx context.Context, cmdID domain.QueuedCommandID, status domain.QueueStatus, result *domain.QueuedCommandResult) error
// GetByID retrieves a specific queued command by ID.
GetByID(ctx context.Context, cmdID domain.QueuedCommandID) (*domain.QueuedCommand, error)
// List returns queued commands for a project with optional filters.
List(ctx context.Context, projectID string, filters *domain.QueueFilters) ([]*domain.QueuedCommand, error)
// Cancel marks a pending command as cancelled.
// Returns an error if the command is not in pending status.
Cancel(ctx context.Context, cmdID domain.QueuedCommandID) error
// GetStats returns queue statistics for a project (or all projects if empty).
GetStats(ctx context.Context, projectID string) (*domain.QueueStats, error)
// CleanupOld removes completed/failed/cancelled commands older than the specified duration.
CleanupOld(ctx context.Context, olderThanDays int) (int64, error)
}