diff --git a/core/services/workflows/syncer/engine_registry.go b/core/services/workflows/syncer/engine_registry.go index 1d32dcf4a66..6dd54794e8b 100644 --- a/core/services/workflows/syncer/engine_registry.go +++ b/core/services/workflows/syncer/engine_registry.go @@ -26,26 +26,26 @@ func (r *engineRegistry) Add(id string, engine *workflows.Engine) { } // Get retrieves an engine from the registry. -func (r *engineRegistry) Get(id string) *workflows.Engine { +func (r *engineRegistry) Get(id string) (*workflows.Engine, error) { r.mu.RLock() defer r.mu.RUnlock() - return r.engines[id] + engine, found := r.engines[id] + if !found { + return nil, errors.New("engine not found") + } + return engine, nil } -// Remove removes an engine from the registry. -func (r *engineRegistry) Remove(id string) error { +// Pop removes an engine from the registry and returns the engine if found. +func (r *engineRegistry) Pop(id string) (*workflows.Engine, error) { r.mu.Lock() defer r.mu.Unlock() engine, ok := r.engines[id] if !ok { - return errors.New("remove failed: engine not found") - } - err := engine.Close() - if err != nil { - return err + return nil, errors.New("remove failed: engine not found") } delete(r.engines, id) - return nil + return engine, nil } // Close closes all engines in the registry.