- Add API server with WebSocket support and REST endpoints - Implement authentication system with API keys and permissions - Add task queue system with Redis backend and error handling - Include storage layer with database migrations and schemas - Add comprehensive logging, metrics, and telemetry - Implement security middleware and network utilities - Add experiment management and container orchestration - Include configuration management with smart defaults
47 lines
1.8 KiB
Go
47 lines
1.8 KiB
Go
package queue
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/jfraeys/fetch_ml/internal/config"
|
|
)
|
|
|
|
// Task represents an ML experiment task
|
|
type Task struct {
|
|
ID string `json:"id"`
|
|
JobName string `json:"job_name"`
|
|
Args string `json:"args"`
|
|
Status string `json:"status"` // queued, running, completed, failed
|
|
Priority int64 `json:"priority"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
StartedAt *time.Time `json:"started_at,omitempty"`
|
|
EndedAt *time.Time `json:"ended_at,omitempty"`
|
|
WorkerID string `json:"worker_id,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
Datasets []string `json:"datasets,omitempty"`
|
|
Metadata map[string]string `json:"metadata,omitempty"`
|
|
|
|
// User ownership and permissions
|
|
UserID string `json:"user_id"` // User who owns this task
|
|
Username string `json:"username"` // Username for display
|
|
CreatedBy string `json:"created_by"` // User who submitted the task
|
|
|
|
// Lease management for task resilience
|
|
LeaseExpiry *time.Time `json:"lease_expiry,omitempty"` // When task lease expires
|
|
LeasedBy string `json:"leased_by,omitempty"` // Worker ID holding lease
|
|
|
|
// Retry management
|
|
RetryCount int `json:"retry_count"` // Number of retry attempts made
|
|
MaxRetries int `json:"max_retries"` // Maximum retry limit (default 3)
|
|
LastError string `json:"last_error,omitempty"` // Last error encountered
|
|
NextRetry *time.Time `json:"next_retry,omitempty"` // When to retry next (exponential backoff)
|
|
}
|
|
|
|
// Redis key constants
|
|
var (
|
|
TaskQueueKey = config.RedisTaskQueueKey
|
|
TaskPrefix = config.RedisTaskPrefix
|
|
TaskStatusPrefix = config.RedisTaskStatusPrefix
|
|
WorkerHeartbeat = config.RedisWorkerHeartbeat
|
|
JobMetricsPrefix = config.RedisJobMetricsPrefix
|
|
)
|