Skip to content

refactor: decompose executor.go into focused modules#3

Merged
simonovic86 merged 1 commit intomainfrom
claude/sweet-tereshkova
Mar 10, 2026
Merged

refactor: decompose executor.go into focused modules#3
simonovic86 merged 1 commit intomainfrom
claude/sweet-tereshkova

Conversation

@simonovic86
Copy link
Owner

Summary

Refactor the large monolithic executor.go file (1119 lines) into focused, single-responsibility modules:

  • executor_api.go (267 lines): Public API methods for command management

    • Add, AddMany, Get, History, Cancel, CancelByTag
    • ReplayFromDLQ, FindDeadLettered, PurgeDLQ, Stats
  • executor_handlers.go (312 lines): Command execution result and error handling

    • handleResult, handleError, handleExpired
    • spawnChildren, spawnBarrier, propagateIDs
  • executor_maintenance.go (228 lines): Background maintenance tasks

    • cleanupLoop, stuckCommandRecoveryLoop, recoverStuckCommands
    • createInstance, mergeSpecs, helper utilities
  • executor_schedule.go (109 lines): Scheduling and timing logic

    • queueSchedule, scheduleDelayed, replay, cancelDelayedTimers
    • startPermanentCommand
  • executor_worker.go (243 lines): Worker execution logic

    • worker, pollingWorker, claimAndExecute, execute
    • safeExecute, executeWithMiddleware

Benefits

  • Improves code organization and maintainability
  • Easier to locate and understand specific functionality
  • Reduces cognitive load when working with the codebase
  • Each file has a clear, focused purpose

Migration

No breaking changes. All methods remain public with identical signatures.

Split the 1,380-line executor.go into 6 files by concern:
- executor.go (260 lines): struct, constructor, Start/Stop, dashboard
- executor_api.go (267): public API — Add, Get, Cancel, DLQ, Stats
- executor_worker.go (243): workers, execute, middleware chain
- executor_handlers.go (312): result/error/expiry handling
- executor_schedule.go (109): scheduling, timers, replay
- executor_maintenance.go (228): cleanup, stuck recovery, instance creation

Also extracted submethods from handleResult() (162 → ~50 lines):
- spawnChildren(): child instance creation and scheduling
- spawnBarrier(): fan-in barrier creation
- propagateIDs(): deduplicated trace/correlation ID propagation

No behavioral changes. All methods remain on *Executor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@simonovic86 simonovic86 merged commit 291a949 into main Mar 10, 2026
3 checks passed
@simonovic86 simonovic86 deleted the claude/sweet-tereshkova branch March 10, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant