Skip to content

Commit

Permalink
revert changes from bad rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpertsov committed Sep 24, 2024
1 parent 8f7613e commit a698991
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions robot/impl/local_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,26 @@ func (r *localRobot) newResource(
}
}
}

if resInfo.Constructor != nil {
return resInfo.Constructor(ctx, deps, conf, gNode.Logger())
}
if resInfo.DeprecatedRobotConstructor == nil {
switch {
case resInfo.Constructor != nil:
res, err = resInfo.Constructor(ctx, deps, conf, gNode.Logger())
case resInfo.DeprecatedRobotConstructor != nil:
res, err = resInfo.DeprecatedRobotConstructor(ctx, r, conf, gNode.Logger())
default:
return nil, errors.Errorf("invariant: no constructor for %q", conf.API)
}
return resInfo.DeprecatedRobotConstructor(ctx, r, conf, gNode.Logger())
if err != nil {
return nil, err
}

// If context has errored, even if construction succeeded we should close the resource and return the context error.
// Use closeContext because otherwise any Close operations that rely on the context will immediately fail.
// The deadline associated with the context passed in to this function is utils.GetResourceConfigurationTimeout.
if ctx.Err() != nil {
r.logger.CDebugw(ctx, "resource successfully constructed but context is done, closing constructed resource")
return nil, multierr.Combine(ctx.Err(), res.Close(r.closeContext))
}
return res, nil
}

func (r *localRobot) updateWeakDependents(ctx context.Context) {
Expand Down Expand Up @@ -1178,14 +1190,26 @@ func (r *localRobot) reconfigure(ctx context.Context, newConfig *config.Config,
// if anything has changed.
err := r.packageManager.Sync(ctx, newConfig.Packages, newConfig.Modules)
if err != nil {
allErrs = multierr.Combine(allErrs, err)
r.Logger().CErrorw(ctx, "reconfiguration aborted because cloud modules or packages download failed", "error", err)
return
}
// For local tarball modules, we create synthetic versions for package management. The `localRobot` keeps track of these because
// config reader would overwrite if we just stored it in config. Here, we copy the synthetic version from the `localRobot` into the
// appropriate `config.Module` object inside the `cfg.Modules` slice. Thus, when a local tarball module is reloaded, the viam-server
// can unpack it into a fresh directory rather than reusing the previous one.
r.applyLocalModuleVersions(newConfig)
allErrs = multierr.Combine(allErrs, r.localPackages.Sync(ctx, newConfig.Packages, newConfig.Modules))
err = r.localPackages.Sync(ctx, newConfig.Packages, newConfig.Modules)
if err != nil {
r.Logger().CErrorw(ctx, "reconfiguration aborted because local modules or packages sync failed", "error", err)
return
}

if newConfig.Cloud != nil {
r.Logger().CDebug(ctx, "updating cached config")
if err := newConfig.StoreToCache(); err != nil {
r.logger.CErrorw(ctx, "error storing the config", "error", err)
}
}

// Add default services and process their dependencies. Dependencies may
// already come from config validation so we check that here.
Expand Down

0 comments on commit a698991

Please sign in to comment.