saving in place
This commit is contained in:
@@ -3,6 +3,7 @@ package lifecycle
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -19,6 +20,7 @@ type ModuleRegistry struct {
|
||||
eventBus EventBus
|
||||
healthMonitor HealthMonitor
|
||||
config RegistryConfig
|
||||
logger *slog.Logger
|
||||
mu sync.RWMutex
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
@@ -252,7 +254,7 @@ func (mr *ModuleRegistry) Register(module Module, config ModuleConfig) error {
|
||||
|
||||
// Publish event
|
||||
if mr.eventBus != nil {
|
||||
mr.eventBus.Publish(ModuleEvent{
|
||||
if err := mr.eventBus.Publish(ModuleEvent{
|
||||
Type: EventModuleRegistered,
|
||||
ModuleID: id,
|
||||
Timestamp: time.Now(),
|
||||
@@ -260,7 +262,9 @@ func (mr *ModuleRegistry) Register(module Module, config ModuleConfig) error {
|
||||
"name": module.GetName(),
|
||||
"version": module.GetVersion(),
|
||||
},
|
||||
})
|
||||
}); err != nil {
|
||||
mr.logger.Error("Failed to publish module registration event", "module_id", id, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -675,19 +679,23 @@ func (mr *ModuleRegistry) stopModule(registered *RegisteredModule) error {
|
||||
|
||||
// Stop health monitoring
|
||||
if mr.healthMonitor != nil {
|
||||
mr.healthMonitor.StopMonitoring(registered.ID)
|
||||
if err := mr.healthMonitor.StopMonitoring(registered.ID); err != nil {
|
||||
mr.logger.Error("Failed to stop health monitoring", "module_id", registered.ID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Publish event
|
||||
if mr.eventBus != nil {
|
||||
mr.eventBus.Publish(ModuleEvent{
|
||||
if err := mr.eventBus.Publish(ModuleEvent{
|
||||
Type: EventModuleStopped,
|
||||
ModuleID: registered.ID,
|
||||
Timestamp: time.Now(),
|
||||
Data: map[string]interface{}{
|
||||
"shutdown_time": registered.Metrics.ShutdownTime,
|
||||
},
|
||||
})
|
||||
}); err != nil {
|
||||
mr.logger.Error("Failed to publish module stopped event", "module_id", registered.ID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user