Skip to content

Commit 55aadad

Browse files
committed
[core] Make environment.Manager single instance accessible from outside
1 parent 0b3af28 commit 55aadad

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

core/environment/manager.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ type Manager struct {
5454
pendingStateChangeCh map[uid.ID]chan *event.TasksStateChangedEvent
5555
}
5656

57+
var (
58+
instance *Manager
59+
)
60+
61+
func ManagerInstance() *Manager {
62+
return instance
63+
}
64+
5765
func NewEnvManager(tm *task.Manager, incomingEventCh <-chan event.Event) *Manager {
58-
envman := &Manager{
66+
instance = &Manager{
5967
m: make(map[uid.ID]*Environment),
6068
taskman: tm,
6169
incomingEventCh: incomingEventCh,
@@ -66,22 +74,22 @@ func NewEnvManager(tm *task.Manager, incomingEventCh <-chan event.Event) *Manage
6674
go func() {
6775
for ;; {
6876
select {
69-
case incomingEvent := <- envman.incomingEventCh:
77+
case incomingEvent := <- instance.incomingEventCh:
7078
switch typedEvent := incomingEvent.(type) {
7179
case event.DeviceEvent:
72-
envman.handleDeviceEvent(typedEvent)
80+
instance.handleDeviceEvent(typedEvent)
7381
case *event.TasksReleasedEvent:
7482
// If we got a TasksReleasedEvent, it must be matched with a pending
7583
// environment teardown.
76-
if thisEnvCh, ok := envman.pendingTeardownsCh[typedEvent.GetEnvironmentId()]; ok {
84+
if thisEnvCh, ok := instance.pendingTeardownsCh[typedEvent.GetEnvironmentId()]; ok {
7785
thisEnvCh <- typedEvent
7886
close(thisEnvCh)
79-
delete(envman.pendingTeardownsCh, typedEvent.GetEnvironmentId())
87+
delete(instance.pendingTeardownsCh, typedEvent.GetEnvironmentId())
8088
}
8189
case *event.TasksStateChangedEvent:
8290
// If we got a TasksStateChangedEvent, it must be matched with a pending
8391
// environment transition.
84-
if thisEnvCh, ok := envman.pendingStateChangeCh[typedEvent.GetEnvironmentId()]; ok {
92+
if thisEnvCh, ok := instance.pendingStateChangeCh[typedEvent.GetEnvironmentId()]; ok {
8593
thisEnvCh <- typedEvent
8694
}
8795
default:
@@ -90,7 +98,7 @@ func NewEnvManager(tm *task.Manager, incomingEventCh <-chan event.Event) *Manage
9098
}
9199
}
92100
}()
93-
return envman
101+
return instance
94102
}
95103

96104
func (envs *Manager) GetActiveDetectors() system.IDMap {

core/the/singleton.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ func RepoManager() *repos.RepoManager {
4141

4242
func BookkeepingAPI() *bookkeeping.BookkeepingWrapper {
4343
return bookkeeping.Instance()
44-
}
44+
}

0 commit comments

Comments
 (0)