Allow configuring retention for build actions
This commit is contained in:
parent
24e2ec0136
commit
edd78667c5
|
@ -478,6 +478,7 @@ void BuildServiceCleanup::run()
|
||||||
|
|
||||||
// get variables from setup
|
// get variables from setup
|
||||||
auto setupLock = m_setup.lockToRead();
|
auto setupLock = m_setup.lockToRead();
|
||||||
|
m_buildActionRetention = m_setup.building.buildActionRetention;
|
||||||
m_paccachePath = findExecutable(m_setup.building.paccachePath);
|
m_paccachePath = findExecutable(m_setup.building.paccachePath);
|
||||||
const auto packageCachePath = m_setup.building.packageCacheDir;
|
const auto packageCachePath = m_setup.building.packageCacheDir;
|
||||||
setupLock.unlock();
|
setupLock.unlock();
|
||||||
|
@ -506,7 +507,7 @@ void BuildServiceCleanup::run()
|
||||||
auto deleted = std::size_t();
|
auto deleted = std::size_t();
|
||||||
constexpr auto stopAt = 150;
|
constexpr auto stopAt = 150;
|
||||||
m_setup.building.forEachBuildAction(
|
m_setup.building.forEachBuildAction(
|
||||||
[this, &count, &deleted, twoWeeksAgo = DateTime::gmtNow() - TimeSpan::fromDays(14)](
|
[this, &count, &deleted, expirationDate = DateTime::gmtNow() - m_buildActionRetention](
|
||||||
LibPkg::StorageID id, BuildAction &action, ServiceSetup::BuildSetup::VisitorBehavior &visitorBehavior) {
|
LibPkg::StorageID id, BuildAction &action, ServiceSetup::BuildSetup::VisitorBehavior &visitorBehavior) {
|
||||||
if (count <= stopAt) {
|
if (count <= stopAt) {
|
||||||
return true; // abort deletion if under 150 build actions anyways
|
return true; // abort deletion if under 150 build actions anyways
|
||||||
|
@ -514,8 +515,9 @@ void BuildServiceCleanup::run()
|
||||||
if (m_buildAction->id == id || action.finished.isNull()) {
|
if (m_buildAction->id == id || action.finished.isNull()) {
|
||||||
return false; // avoid deleting cleanup action itself as well as any unfinished actions
|
return false; // avoid deleting cleanup action itself as well as any unfinished actions
|
||||||
}
|
}
|
||||||
if (action.result != BuildActionResult::Success || action.finished > twoWeeksAgo) {
|
if (action.result != BuildActionResult::Success
|
||||||
return false; // delete only successful actions that are at least two weeks old
|
|| (action.finished > expirationDate && action.type != BuildActionType::BuildServiceCleanup)) {
|
||||||
|
return false; // delete only successful actions that have expired (unless it is just a cleanup action itself)
|
||||||
}
|
}
|
||||||
visitorBehavior = ServiceSetup::BuildSetup::VisitorBehavior::Delete;
|
visitorBehavior = ServiceSetup::BuildSetup::VisitorBehavior::Delete;
|
||||||
++deleted;
|
++deleted;
|
||||||
|
|
|
@ -695,6 +695,7 @@ private:
|
||||||
std::vector<std::pair<std::string, boost::filesystem::path>> m_concreteCacheDirs;
|
std::vector<std::pair<std::string, boost::filesystem::path>> m_concreteCacheDirs;
|
||||||
std::vector<std::pair<std::string, boost::filesystem::path>>::iterator m_concreteCacheDirsIterator;
|
std::vector<std::pair<std::string, boost::filesystem::path>>::iterator m_concreteCacheDirsIterator;
|
||||||
BuildActionMessages m_messages;
|
BuildActionMessages m_messages;
|
||||||
|
CppUtilities::TimeSpan m_buildActionRetention;
|
||||||
bool m_dryCacheCleanup;
|
bool m_dryCacheCleanup;
|
||||||
bool m_dbCleanupConcluded, m_cacheCleanupConcluded;
|
bool m_dbCleanupConcluded, m_cacheCleanupConcluded;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef LIBREPOMGR_HELPER_H
|
#ifndef LIBREPOMGR_HELPER_H
|
||||||
#define LIBREPOMGR_HELPER_H
|
#define LIBREPOMGR_HELPER_H
|
||||||
|
|
||||||
|
#include <c++utilities/chrono/timespan.h>
|
||||||
|
#include <c++utilities/conversion/conversionexception.h>
|
||||||
#include <c++utilities/conversion/stringconversion.h>
|
#include <c++utilities/conversion/stringconversion.h>
|
||||||
#include <c++utilities/io/ansiescapecodes.h>
|
#include <c++utilities/io/ansiescapecodes.h>
|
||||||
#include <c++utilities/misc/traits.h>
|
#include <c++utilities/misc/traits.h>
|
||||||
|
@ -63,7 +65,6 @@ inline void convertValue(const std::multimap<std::string, std::string> &multimap
|
||||||
template <typename TargetType, Traits::EnableIfAny<std::is_integral<TargetType>, Traits::IsSpecializationOf<TargetType, std::atomic>> * = nullptr>
|
template <typename TargetType, Traits::EnableIfAny<std::is_integral<TargetType>, Traits::IsSpecializationOf<TargetType, std::atomic>> * = nullptr>
|
||||||
inline void convertValue(const std::multimap<std::string, std::string> &multimap, const std::string &key, TargetType &result)
|
inline void convertValue(const std::multimap<std::string, std::string> &multimap, const std::string &key, TargetType &result)
|
||||||
{
|
{
|
||||||
using namespace std;
|
|
||||||
using namespace CppUtilities;
|
using namespace CppUtilities;
|
||||||
using namespace CppUtilities::EscapeCodes;
|
using namespace CppUtilities::EscapeCodes;
|
||||||
|
|
||||||
|
@ -75,8 +76,7 @@ inline void convertValue(const std::multimap<std::string, std::string> &multimap
|
||||||
result = stringToNumber<TargetType>(value);
|
result = stringToNumber<TargetType>(value);
|
||||||
}
|
}
|
||||||
} catch (const ConversionException &) {
|
} catch (const ConversionException &) {
|
||||||
cerr << Phrases::ErrorMessage << "Specified number \"" << value << "\" for key \"" << key << "\" is invalid." << Phrases::End;
|
std::cerr << Phrases::ErrorMessage << "Specified number \"" << value << "\" for key \"" << key << "\" is invalid." << Phrases::End;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,16 +90,14 @@ template <> inline void convertValue(const std::multimap<std::string, std::strin
|
||||||
|
|
||||||
template <> inline void convertValue(const std::multimap<std::string, std::string> &multimap, const std::string &key, std::regex &result)
|
template <> inline void convertValue(const std::multimap<std::string, std::string> &multimap, const std::string &key, std::regex &result)
|
||||||
{
|
{
|
||||||
using namespace std;
|
|
||||||
using namespace CppUtilities::EscapeCodes;
|
using namespace CppUtilities::EscapeCodes;
|
||||||
|
|
||||||
if (const char *const value = getLastValue(multimap, key)) {
|
if (const char *const value = getLastValue(multimap, key)) {
|
||||||
try {
|
try {
|
||||||
result = value;
|
result = value;
|
||||||
} catch (const regex_error &e) {
|
} catch (const std::regex_error &e) {
|
||||||
cerr << Phrases::ErrorMessage << "Specified regex \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End;
|
std::cerr << Phrases::ErrorMessage << "Specified regex \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End;
|
||||||
cerr << e.what() << '\n';
|
std::cerr << e.what() << '\n';
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,6 +117,20 @@ template <> inline void convertValue(const std::multimap<std::string, std::strin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <> inline void convertValue(const std::multimap<std::string, std::string> &multimap, const std::string &key, CppUtilities::TimeSpan &result)
|
||||||
|
{
|
||||||
|
using namespace CppUtilities::EscapeCodes;
|
||||||
|
|
||||||
|
if (const char *const value = getLastValue(multimap, key)) {
|
||||||
|
try {
|
||||||
|
result = CppUtilities::TimeSpan::fromString(value);
|
||||||
|
} catch (const CppUtilities::ConversionException &e) {
|
||||||
|
std::cerr << Phrases::ErrorMessage << "Specified duration \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End;
|
||||||
|
std::cerr << e.what() << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename VectorType> void mergeSecondVectorIntoFirstVector(VectorType &firstVector, VectorType &secondVector)
|
template <typename VectorType> void mergeSecondVectorIntoFirstVector(VectorType &firstVector, VectorType &secondVector)
|
||||||
{
|
{
|
||||||
const auto requiredSize = firstVector.size() + secondVector.size();
|
const auto requiredSize = firstVector.size() + secondVector.size();
|
||||||
|
|
|
@ -181,6 +181,7 @@ void ServiceSetup::BuildSetup::applyConfig(const std::multimap<std::string, std:
|
||||||
convertValue(multimap, "package_cache_dir", packageCacheDir);
|
convertValue(multimap, "package_cache_dir", packageCacheDir);
|
||||||
convertValue(multimap, "package_download_size_limit", packageDownloadSizeLimit);
|
convertValue(multimap, "package_download_size_limit", packageDownloadSizeLimit);
|
||||||
convertValue(multimap, "test_files_dir", testFilesDir);
|
convertValue(multimap, "test_files_dir", testFilesDir);
|
||||||
|
convertValue(multimap, "build_action_retention", buildActionRetention);
|
||||||
convertValue(multimap, "load_files_dbs", loadFilesDbs);
|
convertValue(multimap, "load_files_dbs", loadFilesDbs);
|
||||||
convertValue(multimap, "db_path", dbPath);
|
convertValue(multimap, "db_path", dbPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,6 +136,7 @@ struct LIBREPOMGR_EXPORT ServiceSetup : public LibPkg::Lockable {
|
||||||
std::uint64_t packageDownloadSizeLimit = 500 * 1024 * 1024;
|
std::uint64_t packageDownloadSizeLimit = 500 * 1024 * 1024;
|
||||||
std::string testFilesDir;
|
std::string testFilesDir;
|
||||||
BuildPresets presets;
|
BuildPresets presets;
|
||||||
|
CppUtilities::TimeSpan buildActionRetention = CppUtilities::TimeSpan::fromDays(14);
|
||||||
bool loadFilesDbs = false;
|
bool loadFilesDbs = false;
|
||||||
bool forceLoadingDbs = false;
|
bool forceLoadingDbs = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue