refactor(core): remove scheduler and simplify app lifecycle

- Delete scheduler.go and scheduler_test.go (no longer needed)
- Simplify App struct by removing Handler interface dependency
- Remove StartScheduler/StopScheduler from app lifecycle
- Update main.go to not pass handler to app constructor
- Remove scheduler mock from app tests, simplify test coverage
This commit is contained in:
2026-02-28 12:56:59 -05:00
parent 877fccbb52
commit 4d0d86838a
5 changed files with 7 additions and 737 deletions
+1 -30
View File
@@ -12,26 +12,18 @@ import (
"github.com/labstack/echo/v4"
)
// Handler interface for services that need lifecycle management
type Handler interface {
StartScheduler()
StopScheduler()
}
// App manages application lifecycle and graceful shutdown
type App struct {
echo *echo.Echo
handler Handler
shutdownTimeout time.Duration
shutdownMutex sync.Mutex
shutdownDone chan struct{}
}
// New creates a new App instance
func New(echo *echo.Echo, handler Handler) *App {
func New(echo *echo.Echo) *App {
return &App{
echo: echo,
handler: handler,
shutdownTimeout: 30 * time.Second,
shutdownDone: make(chan struct{}),
}
@@ -41,9 +33,6 @@ func New(echo *echo.Echo, handler Handler) *App {
func (a *App) Start() error {
log.Println("Starting application lifecycle management...")
// Start background services
a.startBackgroundServices()
// Setup signal handling for graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan,
@@ -66,20 +55,6 @@ func (a *App) Start() error {
return nil
}
// startBackgroundServices starts all background services
func (a *App) startBackgroundServices() {
log.Println("Starting background services...")
// Start scheduler for auto-scanning
go func() {
a.handler.StartScheduler()
log.Println("Scheduler started")
}()
// Note: Watch mode is started by the handlers package
// after a 2-second delay, so we don't duplicate it here
}
// Shutdown performs graceful shutdown of all services
func (a *App) Shutdown() error {
a.shutdownMutex.Lock()
@@ -112,10 +87,6 @@ func (a *App) Shutdown() error {
log.Printf("Error stopping HTTP server: %v", err)
}
// Stop scheduler
log.Println("Stopping scheduler...")
a.handler.StopScheduler()
log.Println("All services stopped")
}()