Added the ability to set the scraper retry count and timer settings from the user interface.

This commit is contained in:
Leon Styhre 2023-02-11 12:32:51 +01:00
parent 0ececf65bb
commit 3cb0b6a644
3 changed files with 59 additions and 17 deletions

View file

@ -14,6 +14,7 @@
#include "FileSorts.h"
#include "SystemData.h"
#include "components/OptionListComponent.h"
#include "components/SliderComponent.h"
#include "components/SwitchComponent.h"
#include "guis/GuiMsgBox.h"
#include "guis/GuiOfflineGenerator.h"
@ -758,6 +759,42 @@ void GuiScraperMenu::openOtherOptions()
->setOpacity(DISABLED_OPACITY);
}
// Automatic retries on error.
auto scraperRetryOnErrorCount = std::make_shared<SliderComponent>(0.0f, 10.0f, 1.0f);
scraperRetryOnErrorCount->setValue(
static_cast<float>(Settings::getInstance()->getInt("ScraperRetryOnErrorCount")));
s->addWithLabel("AUTOMATIC RETRIES ON ERROR", scraperRetryOnErrorCount);
s->addSaveFunc([scraperRetryOnErrorCount, s] {
if (scraperRetryOnErrorCount->getValue() !=
static_cast<float>(Settings::getInstance()->getInt("ScraperRetryOnErrorCount"))) {
Settings::getInstance()->setInt("ScraperRetryOnErrorCount",
static_cast<int>(scraperRetryOnErrorCount->getValue()));
s->setNeedsSaving();
}
});
// Retry attempt timer.
auto scraperRetryOnErrorTimer = std::make_shared<SliderComponent>(1.0f, 30.0f, 1.0f, "s");
scraperRetryOnErrorTimer->setValue(
static_cast<float>(Settings::getInstance()->getInt("ScraperRetryOnErrorTimer")));
s->addWithLabel("RETRY ATTEMPT TIMER", scraperRetryOnErrorTimer);
s->addSaveFunc([scraperRetryOnErrorTimer, s] {
if (scraperRetryOnErrorTimer->getValue() !=
static_cast<float>(Settings::getInstance()->getInt("ScraperRetryOnErrorTimer"))) {
Settings::getInstance()->setInt("ScraperRetryOnErrorTimer",
static_cast<int>(scraperRetryOnErrorTimer->getValue()));
s->setNeedsSaving();
}
});
if (scraperRetryOnErrorCount->getValue() == 0.0f) {
scraperRetryOnErrorTimer->setEnabled(false);
scraperRetryOnErrorTimer->setOpacity(DISABLED_OPACITY);
scraperRetryOnErrorTimer->getParent()
->getChild(scraperRetryOnErrorTimer->getChildIndex() - 1)
->setOpacity(DISABLED_OPACITY);
}
// Overwrite files and data.
auto scraperOverwriteData = std::make_shared<SwitchComponent>();
scraperOverwriteData->setState(Settings::getInstance()->getBool("ScraperOverwriteData"));
@ -942,18 +979,23 @@ void GuiScraperMenu::openOtherOptions()
->setOpacity(DISABLED_OPACITY);
}
// Automatic retry on error.
auto scraperRetryOnError = std::make_shared<SwitchComponent>();
scraperRetryOnError->setState(Settings::getInstance()->getBool("ScraperRetryOnError"));
s->addWithLabel("AUTOMATIC RETRY ON ERROR", scraperRetryOnError);
s->addSaveFunc([scraperRetryOnError, s] {
if (scraperRetryOnError->getState() !=
Settings::getInstance()->getBool("ScraperRetryOnError")) {
Settings::getInstance()->setBool("ScraperRetryOnError",
scraperRetryOnError->getState());
s->setNeedsSaving();
// Slider callback.
auto scraperRetryCountFunc = [scraperRetryOnErrorCount, scraperRetryOnErrorTimer]() {
if (scraperRetryOnErrorCount->getValue() == 0.0f) {
scraperRetryOnErrorTimer->setEnabled(false);
scraperRetryOnErrorTimer->setOpacity(DISABLED_OPACITY);
scraperRetryOnErrorTimer->getParent()
->getChild(scraperRetryOnErrorTimer->getChildIndex() - 1)
->setOpacity(DISABLED_OPACITY);
}
});
else {
scraperRetryOnErrorTimer->setEnabled(true);
scraperRetryOnErrorTimer->setOpacity(1.0f);
scraperRetryOnErrorTimer->getParent()
->getChild(scraperRetryOnErrorTimer->getChildIndex() - 1)
->setOpacity(1.0f);
}
};
// Switch callbacks.
auto interactiveToggleFunc = [scraperSemiautomatic]() {
@ -990,6 +1032,7 @@ void GuiScraperMenu::openOtherOptions()
}
};
scraperRetryOnErrorCount->setCallback(scraperRetryCountFunc);
scraperInteractive->setCallback(interactiveToggleFunc);
scraperRespectExclusions->setCallback(excludeRecursivelyToggleFunc);

View file

@ -47,7 +47,7 @@ GuiScraperSearch::GuiScraperSearch(SearchType type, unsigned int scrapeCount)
, mRetrySearch {false}
, mRetryCount {0}
, mRetryTimer {glm::clamp(
Settings::getInstance()->getInt("ScraperRetryOnErrorTimer") * 1000, 1000, 60000)}
Settings::getInstance()->getInt("ScraperRetryOnErrorTimer") * 1000, 1000, 30000)}
, mRetryAccumulator {0}
{
addChild(&mGrid);
@ -499,8 +499,8 @@ void GuiScraperSearch::onSearchDone(std::vector<ScraperSearchResult>& results)
void GuiScraperSearch::onSearchError(const std::string& error, HttpReq::Status status)
{
const int retries {
glm::clamp(Settings::getInstance()->getInt("ScraperRetryOnErrorCount"), 1, 20)};
if (Settings::getInstance()->getBool("ScraperRetryOnError") && mRetryCount < retries) {
glm::clamp(Settings::getInstance()->getInt("ScraperRetryOnErrorCount"), 0, 10)};
if (retries > 0 && mRetryCount < retries) {
LOG(LogError) << "GuiScraperSearch: " << Utils::String::replace(error, "\n", "");
mRetrySearch = true;
++mRetryCount;

View file

@ -137,6 +137,8 @@ void Settings::setDefaults()
mStringMap["ScraperRegion"] = {"eu", "eu"};
mStringMap["ScraperLanguage"] = {"en", "en"};
mIntMap["ScraperRetryOnErrorCount"] = {3, 3};
mIntMap["ScraperRetryOnErrorTimer"] = {3, 3};
mBoolMap["ScraperOverwriteData"] = {true, true};
mBoolMap["ScraperHaltOnInvalidMedia"] = {true, true};
mBoolMap["ScraperSearchMetadataName"] = {true, true};
@ -148,7 +150,6 @@ void Settings::setDefaults()
mBoolMap["ScraperConvertUnderscores"] = {true, true};
mBoolMap["ScraperAutomaticRemoveDots"] = {true, true};
mBoolMap["ScraperRegionFallback"] = {true, true};
mBoolMap["ScraperRetryOnError"] = {true, true};
// UI settings.
mStringMap["ThemeSet"] = {"slate-es-de", "slate-es-de"};
@ -321,8 +322,6 @@ void Settings::setDefaults()
mIntMap["LottieMaxTotalCache"] = {1024, 1024};
mIntMap["ScraperConnectionTimeout"] = {30, 30};
mIntMap["ScraperTransferTimeout"] = {120, 120};
mIntMap["ScraperRetryOnErrorCount"] = {5, 5};
mIntMap["ScraperRetryOnErrorTimer"] = {5, 5};
//
// Hardcoded or program-internal settings.