Skip to content

Commit

Permalink
feat: watcher continuity
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Bianconi committed Feb 3, 2023
1 parent 2e2e2b6 commit 2df98f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions arduino/discovery/discoverymanager/discoverymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (dm *DiscoveryManager) Clear() {
dm.discoveries = map[string]*discovery.PluggableDiscovery{}
}

// DiscoveryRunning returns boolean representing the running status of discoveries
func (dm *DiscoveryManager) DiscoveryRunning() bool {
// AreDiscoveriesRunning returns a boolean representing the running status of discoveries
func (dm *DiscoveryManager) AreDiscoveriesRunning() bool {
return dm.discoveriesRunning
}

Expand Down Expand Up @@ -206,7 +206,7 @@ func (dm *DiscoveryManager) startDiscovery(d *discovery.PluggableDiscovery) (dis
// here from discovery to discovery manager
dm.feed <- ev
}
logrus.Info("Discovery event channel closed %s. Exiting goroutine.", d.GetID())
logrus.Infof("Discovery event channel closed %s. Exiting goroutine.", d.GetID())
}(d)
return nil
}
Expand Down
27 changes: 17 additions & 10 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,17 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
},
})
}
var shouldStartDiscovery bool
var shouldRestartDiscovery bool
{
// We need to rebuild the PackageManager currently in use by this instance
// in case this is not the first Init on this instances, that might happen
// after reinitializing an instance after installing or uninstalling a core.
// If this is not done the information of the uninstall core is kept in memory,
// even if it should not.

exp, release := instance.pm.NewExplorer()
// register whether the discoveries are running, if so we need to start them in
// for the previous watchers to keep receiving events
if exp.DiscoveryManager() != nil && exp.DiscoveryManager().DiscoveryRunning() {
shouldStartDiscovery = true
} else {
shouldStartDiscovery = false
}
release()
// order for the previous watchers to keep receiving events
shouldRestartDiscovery = areDiscoveriesRunning(instance.pm)
pmb, commitPackageManager := instance.pm.NewBuilder()

loadBuiltinTools := func() []error {
Expand Down Expand Up @@ -453,7 +447,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
responseError(s)
}

if shouldStartDiscovery {
if shouldRestartDiscovery {
pme.DiscoveryManager().Start()
}
// Refreshes the locale used, this will change the
Expand All @@ -464,6 +458,19 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
return nil
}

func areDiscoveriesRunning(pm *packagemanager.PackageManager) bool {
if pm == nil {
return false
}
exp, release := pm.NewExplorer()
defer release()

if exp.DiscoveryManager() != nil && exp.DiscoveryManager().AreDiscoveriesRunning() {
return true
}
return false
}

// Destroy FIXMEDOC
func Destroy(ctx context.Context, req *rpc.DestroyRequest) (*rpc.DestroyResponse, error) {
if ok := instances.RemoveID(req.GetInstance().GetId()); !ok {
Expand Down

0 comments on commit 2df98f1

Please sign in to comment.