Skip to content

Commit

Permalink
chore(workflows): stubs out engine registry
Browse files Browse the repository at this point in the history
  • Loading branch information
MStreet3 committed Nov 21, 2024
1 parent 4f88ad1 commit 809788d
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions core/services/workflows/syncer/engine_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package syncer

import (
"errors"
"sync"

"github.com/smartcontractkit/chainlink/v2/core/services/workflows"
)

type engineRegistry struct {

Check failure on line 10 in core/services/workflows/syncer/engine_registry.go

View workflow job for this annotation

GitHub Actions / lint

type `engineRegistry` is unused (unused)
engines map[string]*workflows.Engine
mu sync.RWMutex
}

func newEngineRegistry() *engineRegistry {

Check failure on line 15 in core/services/workflows/syncer/engine_registry.go

View workflow job for this annotation

GitHub Actions / lint

func `newEngineRegistry` is unused (unused)
return &engineRegistry{
engines: make(map[string]*workflows.Engine),
}
}

// Add adds an engine to the registry.
func (r *engineRegistry) Add(id string, engine *workflows.Engine) {

Check failure on line 22 in core/services/workflows/syncer/engine_registry.go

View workflow job for this annotation

GitHub Actions / lint

func `(*engineRegistry).Add` is unused (unused)
r.mu.Lock()
defer r.mu.Unlock()
r.engines[id] = engine
}

// Get retrieves an engine from the registry.
func (r *engineRegistry) Get(id string) *workflows.Engine {

Check failure on line 29 in core/services/workflows/syncer/engine_registry.go

View workflow job for this annotation

GitHub Actions / lint

func `(*engineRegistry).Get` is unused (unused)
r.mu.RLock()
defer r.mu.RUnlock()
return r.engines[id]
}

// Remove removes an engine from the registry.
func (r *engineRegistry) Remove(id string) error {

Check failure on line 36 in core/services/workflows/syncer/engine_registry.go

View workflow job for this annotation

GitHub Actions / lint

func `(*engineRegistry).Remove` is unused (unused)
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
}
delete(r.engines, id)
return nil
}

// Close closes all engines in the registry.
func (r *engineRegistry) Close() error {

Check failure on line 52 in core/services/workflows/syncer/engine_registry.go

View workflow job for this annotation

GitHub Actions / lint

func `(*engineRegistry).Close` is unused (unused)
r.mu.Lock()
defer r.mu.Unlock()
var err error
for id, engine := range r.engines {
closeErr := engine.Close()
if closeErr != nil {
err = errors.Join(err, closeErr)
}
delete(r.engines, id)
}
return err
}

0 comments on commit 809788d

Please sign in to comment.