Skip to content

Commit 2df98f1

Browse files
author
Luca Bianconi
committed
feat: watcher continuity
1 parent 2e2e2b6 commit 2df98f1

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

Diff for: arduino/discovery/discoverymanager/discoverymanager.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func (dm *DiscoveryManager) Clear() {
6969
dm.discoveries = map[string]*discovery.PluggableDiscovery{}
7070
}
7171

72-
// DiscoveryRunning returns boolean representing the running status of discoveries
73-
func (dm *DiscoveryManager) DiscoveryRunning() bool {
72+
// AreDiscoveriesRunning returns a boolean representing the running status of discoveries
73+
func (dm *DiscoveryManager) AreDiscoveriesRunning() bool {
7474
return dm.discoveriesRunning
7575
}
7676

@@ -206,7 +206,7 @@ func (dm *DiscoveryManager) startDiscovery(d *discovery.PluggableDiscovery) (dis
206206
// here from discovery to discovery manager
207207
dm.feed <- ev
208208
}
209-
logrus.Info("Discovery event channel closed %s. Exiting goroutine.", d.GetID())
209+
logrus.Infof("Discovery event channel closed %s. Exiting goroutine.", d.GetID())
210210
}(d)
211211
return nil
212212
}

Diff for: commands/instances.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,17 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
261261
},
262262
})
263263
}
264-
var shouldStartDiscovery bool
264+
var shouldRestartDiscovery bool
265265
{
266266
// We need to rebuild the PackageManager currently in use by this instance
267267
// in case this is not the first Init on this instances, that might happen
268268
// after reinitializing an instance after installing or uninstalling a core.
269269
// If this is not done the information of the uninstall core is kept in memory,
270270
// even if it should not.
271271

272-
exp, release := instance.pm.NewExplorer()
273272
// register whether the discoveries are running, if so we need to start them in
274-
// for the previous watchers to keep receiving events
275-
if exp.DiscoveryManager() != nil && exp.DiscoveryManager().DiscoveryRunning() {
276-
shouldStartDiscovery = true
277-
} else {
278-
shouldStartDiscovery = false
279-
}
280-
release()
273+
// order for the previous watchers to keep receiving events
274+
shouldRestartDiscovery = areDiscoveriesRunning(instance.pm)
281275
pmb, commitPackageManager := instance.pm.NewBuilder()
282276

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

456-
if shouldStartDiscovery {
450+
if shouldRestartDiscovery {
457451
pme.DiscoveryManager().Start()
458452
}
459453
// Refreshes the locale used, this will change the
@@ -464,6 +458,19 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
464458
return nil
465459
}
466460

461+
func areDiscoveriesRunning(pm *packagemanager.PackageManager) bool {
462+
if pm == nil {
463+
return false
464+
}
465+
exp, release := pm.NewExplorer()
466+
defer release()
467+
468+
if exp.DiscoveryManager() != nil && exp.DiscoveryManager().AreDiscoveriesRunning() {
469+
return true
470+
}
471+
return false
472+
}
473+
467474
// Destroy FIXMEDOC
468475
func Destroy(ctx context.Context, req *rpc.DestroyRequest) (*rpc.DestroyResponse, error) {
469476
if ok := instances.RemoveID(req.GetInstance().GetId()); !ok {

0 commit comments

Comments
 (0)