From ae0a370fb4359f840acb588fb3dd14cc556bb0b3 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Tue, 17 Feb 2026 14:10:03 -0500 Subject: [PATCH] refactor: Phase 1 - Extract worker interfaces Created interfaces package to break tight coupling: 1. internal/worker/interfaces/executor.go (30 lines) - JobExecutor interface for job execution - ExecutionEnv struct for execution context - ExecutionResult struct for results 2. internal/worker/interfaces/tracker.go (20 lines) - ProgressTracker interface for execution stages - StageStart, StageComplete, StageFailed methods - JobComplete for final status 3. internal/worker/interfaces/manifest.go (18 lines) - ManifestWriter interface for manifest operations - Upsert method for update/create - BuildInitial method for creating new manifests These interfaces will enable: - Dependency injection in future phases - Mocking for unit tests - Clean separation between orchestration and execution Build status: Compiles successfully --- internal/worker/interfaces/executor.go | 33 ++++++++++++++++++++++++++ internal/worker/interfaces/manifest.go | 17 +++++++++++++ internal/worker/interfaces/tracker.go | 21 ++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 internal/worker/interfaces/executor.go create mode 100644 internal/worker/interfaces/manifest.go create mode 100644 internal/worker/interfaces/tracker.go diff --git a/internal/worker/interfaces/executor.go b/internal/worker/interfaces/executor.go new file mode 100644 index 0000000..7cbdc3d --- /dev/null +++ b/internal/worker/interfaces/executor.go @@ -0,0 +1,33 @@ +// Package interfaces defines the contracts for worker components +package interfaces + +import ( + "context" + "time" + + "github.com/jfraeys/fetch_ml/internal/queue" +) + +// ExecutionEnv holds the environment for job execution +type ExecutionEnv struct { + JobDir string + OutputDir string + LogFile string + GPUDevices []string + GPUEnvVar string + GPUDevicesStr string +} + +// JobExecutor defines the contract for executing jobs +type JobExecutor interface { + // Execute runs a job with the given context, task, and environment + Execute(ctx context.Context, task *queue.Task, env ExecutionEnv) error +} + +// ExecutionResult holds the result of job execution +type ExecutionResult struct { + Success bool + ExitCode int + Duration time.Duration + Error error +} diff --git a/internal/worker/interfaces/manifest.go b/internal/worker/interfaces/manifest.go new file mode 100644 index 0000000..411fa49 --- /dev/null +++ b/internal/worker/interfaces/manifest.go @@ -0,0 +1,17 @@ +// Package interfaces defines the contracts for worker components +package interfaces + +import ( + "github.com/jfraeys/fetch_ml/internal/manifest" + "github.com/jfraeys/fetch_ml/internal/queue" +) + +// ManifestWriter defines the contract for writing run manifests +type ManifestWriter interface { + // Upsert updates or creates a manifest in the given directory + // The mutate function is called with the current or new manifest + Upsert(dir string, task *queue.Task, mutate func(*manifest.RunManifest)) + + // BuildInitial creates a new initial manifest for a task + BuildInitial(task *queue.Task, podmanImage string) *manifest.RunManifest +} diff --git a/internal/worker/interfaces/tracker.go b/internal/worker/interfaces/tracker.go new file mode 100644 index 0000000..24bd95e --- /dev/null +++ b/internal/worker/interfaces/tracker.go @@ -0,0 +1,21 @@ +// Package interfaces defines the contracts for worker components +package interfaces + +import ( + "time" +) + +// ProgressTracker defines the contract for tracking job execution progress +type ProgressTracker interface { + // StageStart marks the beginning of an execution stage + StageStart(taskID, stage string) + + // StageComplete marks successful completion of a stage + StageComplete(taskID, stage string, duration time.Duration) + + // StageFailed marks a stage failure + StageFailed(taskID, stage string, err error) + + // JobComplete marks job completion with final status + JobComplete(taskID string, success bool, duration time.Duration) +}