rdev/internal/port/work_queue.go
jordan bc47e426b0 feat: Add CI pipeline proxy, DNS alias management, and worker executor system
- Add ListPipelines/GetPipeline to CIProvider port with Woodpecker adapter
- Add DNS alias endpoints: GET/POST/DELETE /projects/{id}/domains
- Implement worker executor daemon, build executor, and git operations
- Add build service, worker service, and build audit tracking
- Add worker registry with PostgreSQL adapter and migration
- Add multi-provider code agent interface (Claude Code + OpenCode)
- Add create-and-build combo endpoint
- Update landing-page cookbook to reflect all gaps closed
- Fix tech debt: unified validation, auth scopes, error wrapping, slog patterns

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 21:05:28 -07:00

51 lines
2.1 KiB
Go

// Package port defines interfaces (ports) for external dependencies.
package port
import (
"context"
"time"
"github.com/orchard9/rdev/internal/domain"
)
// WorkQueue defines operations for the worker pool task queue.
// Unlike CommandQueue (project-specific claudebox commands), WorkQueue
// supports generic tasks that any worker in the pool can claim and execute.
type WorkQueue interface {
// Enqueue adds a task to the queue.
// Returns the task ID.
Enqueue(ctx context.Context, task *domain.WorkTask) (string, error)
// Dequeue atomically claims the next available task for a worker.
// Uses FOR UPDATE SKIP LOCKED for concurrent worker safety.
// Returns nil if no tasks are available.
Dequeue(ctx context.Context, workerID string) (*domain.WorkTask, error)
// Complete marks a task as successfully completed with results.
Complete(ctx context.Context, taskID string, result *domain.WorkResult) error
// Fail marks a task as failed with an error message.
// If retry_count < max_retries, the task will be re-queued as pending.
Fail(ctx context.Context, taskID string, errMsg string) error
// Cancel marks a pending task as cancelled.
// Returns an error if the task is not in pending status.
Cancel(ctx context.Context, taskID string) error
// GetTask retrieves a task by ID.
GetTask(ctx context.Context, taskID string) (*domain.WorkTask, error)
// ListByProject returns tasks for a project with optional status filter and pagination.
ListByProject(ctx context.Context, projectID string, status *domain.WorkTaskStatus, opts domain.WorkListOptions) (*domain.WorkListResult, error)
// GetStats returns queue statistics.
GetStats(ctx context.Context) (*domain.WorkQueueStats, error)
// CleanupOld removes completed/failed/cancelled tasks older than the specified duration.
CleanupOld(ctx context.Context, olderThan time.Duration) (int64, error)
// RequeueStale re-queues tasks that have been running longer than the timeout.
// This handles workers that crashed without reporting completion.
RequeueStale(ctx context.Context, timeout time.Duration) (int64, error)
}