Skip to content

Commit

Permalink
Merge pull request #375 from foundriesio/cache-app-fetch-check-res
Browse files Browse the repository at this point in the history
Cache app fetch check result
  • Loading branch information
mike-sul authored Dec 9, 2024
2 parents 79ac5f8 + 9539ae8 commit d22975e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/composeapp/appengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ static bool checkAppStatus(const AppEngine::App& app, const Json::Value& status)
AppEngine::Result AppEngine::fetch(const App& app) {
Result res{false};
try {
// If a given app was fetched before, then don't consider it as a fetched app if a caller tries to fetch it again
// for one reason or another - hence remove it from the set of fetched apps.
fetched_apps_.erase(app.uri);
if (local_source_path_.empty()) {
exec(boost::format{"%s --store %s pull -p %s --storage-usage-watermark %d"} % composectl_cmd_ % storeRoot() %
app.uri % storage_watermark_,
Expand All @@ -24,6 +27,7 @@ AppEngine::Result AppEngine::fetch(const App& app) {
"failed to pull compose app");
}
res = true;
fetched_apps_.insert(app.uri);
} catch (const ExecError& exc) {
if (exc.ExitCode == static_cast<int>(ExitCode::ExitCodeInsufficientSpace)) {
const auto usage_stat{Utils::parseJSON(exc.StdErr)};
Expand All @@ -40,6 +44,7 @@ AppEngine::Result AppEngine::fetch(const App& app) {

void AppEngine::remove(const App& app) {
try {
fetched_apps_.erase(app.uri);
// "App removal" in this context refers to deleting app images from the Docker store
// and removing the app compose project (app uninstall).
// Unused app blobs will be removed from the blob store via the prune() method,
Expand Down Expand Up @@ -114,6 +119,7 @@ void AppEngine::prune(const Apps& app_shortlist) {
}
}
for (const auto& app : apps_to_prune) {
fetched_apps_.erase(app.uri);
exec(boost::format{"%s --store %s rm %s --prune=false --quiet"} % composectl_cmd_ % storeRoot() % app.uri,
"failed to remove app");
}
Expand Down Expand Up @@ -143,6 +149,9 @@ void AppEngine::prune(const Apps& app_shortlist) {

bool AppEngine::isAppFetched(const App& app) const {
bool res{false};
if (fetched_apps_.count(app.uri) > 0) {
return true;
}
try {
std::future<std::string> output;
exec(boost::format{"%s --store %s check %s --local --format json"} % composectl_cmd_ % storeRoot() % app.uri, "",
Expand All @@ -152,6 +161,7 @@ bool AppEngine::isAppFetched(const App& app) const {
if (app_fetch_status.isMember("fetch_check") && app_fetch_status["fetch_check"].isMember("missing_blobs") &&
app_fetch_status["fetch_check"]["missing_blobs"].empty()) {
res = true;
fetched_apps_.insert(app.uri);
}
} catch (const ExecError& exc) {
LOG_DEBUG << "app is not fully fetched; app: " << app.name << ", status: " << exc.what();
Expand Down
1 change: 1 addition & 0 deletions src/composeapp/appengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AppEngine : public Docker::RestorableAppEngine {
const std::string composectl_cmd_;
const int storage_watermark_;
const std::string local_source_path_;
mutable std::set<std::string> fetched_apps_;
};

} // namespace composeapp
Expand Down

0 comments on commit d22975e

Please sign in to comment.