Skip to content

Commit 56542bc

Browse files
authored
RSDK-11067: remove resource on alwaysrebuild (#458)
1 parent f5ce69a commit 56542bc

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/viam/sdk/module/service.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
8383
} catch (const std::exception& exc) {
8484
return grpc::Status(::grpc::INTERNAL, exc.what());
8585
}
86-
};
86+
}
87+
8788
try {
8889
parent.server_->add_resource(res, ctx->deadline());
8990
} catch (const std::exception& exc) {
@@ -129,16 +130,18 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
129130
}
130131

131132
const std::shared_ptr<const ModelRegistration> reg =
132-
Registry::get().lookup_model(cfg.name());
133+
Registry::get().lookup_model(cfg.api(), cfg.model());
133134

134-
// TODO RSDK-11067 new resource gets constructed while old one is still alive.
135-
if (reg) {
136-
try {
137-
const std::shared_ptr<Resource> resource = reg->construct_resource(deps, cfg);
138-
manager->replace_one(cfg.resource_name(), resource);
139-
} catch (const std::exception& exc) {
140-
return grpc::Status(::grpc::INTERNAL, exc.what());
141-
}
135+
if (!reg) {
136+
return grpc::Status(::grpc::INTERNAL,
137+
"Unable to rebuild resource: model registration not found");
138+
}
139+
140+
try {
141+
std::shared_ptr<Resource> resource = reg->construct_resource(deps, cfg);
142+
manager->replace_one(cfg.resource_name(), std::move(resource));
143+
} catch (const std::exception& exc) {
144+
return grpc::Status(::grpc::INTERNAL, exc.what());
142145
}
143146

144147
return grpc::Status();

src/viam/sdk/resource/resource_manager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void ResourceManager::do_remove(const Name& name) {
108108
ErrorCondition::k_resource_not_found,
109109
"Attempted to remove resource " + name.to_string() + " but it didn't exist!");
110110
}
111+
111112
resources_.erase(short_name);
112113

113114
std::string const shortcut = get_shortcut_name(short_name);
@@ -135,8 +136,8 @@ void ResourceManager::remove(const Name& name) {
135136
do_remove(name);
136137
} catch (std::exception& exc) {
137138
VIAM_SDK_LOG(error) << "unable to remove resource: " << exc.what();
138-
};
139-
};
139+
}
140+
}
140141

141142
void ResourceManager::replace_one(const Name& name, std::shared_ptr<Resource> resource) {
142143
const std::lock_guard<std::mutex> lock(lock_);

0 commit comments

Comments
 (0)