mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:00:05 +00:00
Automatically refresh placefiles that failed to load
This commit is contained in:
parent
d92f6c7204
commit
06a2a18c06
2 changed files with 48 additions and 4 deletions
|
|
@ -105,6 +105,8 @@ public:
|
||||||
|
|
||||||
void CancelRefresh();
|
void CancelRefresh();
|
||||||
void ScheduleRefresh();
|
void ScheduleRefresh();
|
||||||
|
void ScheduleRefresh(
|
||||||
|
const std::chrono::system_clock::duration timeUntilNextUpdate);
|
||||||
void Update();
|
void Update();
|
||||||
void UpdateAsync();
|
void UpdateAsync();
|
||||||
|
|
||||||
|
|
@ -150,6 +152,8 @@ public:
|
||||||
|
|
||||||
std::string lastRadarSite_ {};
|
std::string lastRadarSite_ {};
|
||||||
std::chrono::system_clock::time_point lastUpdateTime_ {};
|
std::chrono::system_clock::time_point lastUpdateTime_ {};
|
||||||
|
|
||||||
|
std::size_t failureCount_ {};
|
||||||
};
|
};
|
||||||
|
|
||||||
PlacefileManager::PlacefileManager() : p(std::make_unique<Impl>(this))
|
PlacefileManager::PlacefileManager() : p(std::make_unique<Impl>(this))
|
||||||
|
|
@ -542,6 +546,11 @@ void PlacefileManager::Impl::PlacefileRecord::Update()
|
||||||
if (url.isLocalFile())
|
if (url.isLocalFile())
|
||||||
{
|
{
|
||||||
updatedPlacefile = gr::Placefile::Load(name);
|
updatedPlacefile = gr::Placefile::Load(name);
|
||||||
|
|
||||||
|
if (updatedPlacefile == nullptr)
|
||||||
|
{
|
||||||
|
logger_->error("Local placefile not found: {}", name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -625,6 +634,7 @@ void PlacefileManager::Impl::PlacefileRecord::Update()
|
||||||
placefile_ = updatedPlacefile;
|
placefile_ = updatedPlacefile;
|
||||||
title_ = placefile_->title();
|
title_ = placefile_->title();
|
||||||
lastUpdateTime_ = std::chrono::system_clock::now();
|
lastUpdateTime_ = std::chrono::system_clock::now();
|
||||||
|
failureCount_ = 0;
|
||||||
|
|
||||||
// Update font resources
|
// Update font resources
|
||||||
{
|
{
|
||||||
|
|
@ -645,10 +655,30 @@ void PlacefileManager::Impl::PlacefileRecord::Update()
|
||||||
// Notify slots of the placefile update
|
// Notify slots of the placefile update
|
||||||
Q_EMIT p->self_->PlacefileUpdated(name);
|
Q_EMIT p->self_->PlacefileUpdated(name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Update refresh timer
|
// Update refresh timer
|
||||||
ScheduleRefresh();
|
ScheduleRefresh();
|
||||||
|
}
|
||||||
|
else if (enabled_)
|
||||||
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
++failureCount_;
|
||||||
|
|
||||||
|
// Update refresh timer if the file failed to load, in case it is able to
|
||||||
|
// be resolved later
|
||||||
|
if (url.isLocalFile())
|
||||||
|
{
|
||||||
|
ScheduleRefresh(10s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Start attempting to refresh at 15 seconds, and start backing off
|
||||||
|
// until retrying every 60 seconds
|
||||||
|
ScheduleRefresh(
|
||||||
|
std::min<std::chrono::seconds>(15s * failureCount_, 60s));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh()
|
void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh()
|
||||||
|
|
@ -666,6 +696,12 @@ void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh()
|
||||||
auto nextUpdateTime = lastUpdateTime_ + refresh_time();
|
auto nextUpdateTime = lastUpdateTime_ + refresh_time();
|
||||||
auto timeUntilNextUpdate = nextUpdateTime - std::chrono::system_clock::now();
|
auto timeUntilNextUpdate = nextUpdateTime - std::chrono::system_clock::now();
|
||||||
|
|
||||||
|
ScheduleRefresh(timeUntilNextUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh(
|
||||||
|
const std::chrono::system_clock::duration timeUntilNextUpdate)
|
||||||
|
{
|
||||||
logger_->debug(
|
logger_->debug(
|
||||||
"Scheduled refresh in {:%M:%S} ({})",
|
"Scheduled refresh in {:%M:%S} ({})",
|
||||||
std::chrono::duration_cast<std::chrono::seconds>(timeUntilNextUpdate),
|
std::chrono::duration_cast<std::chrono::seconds>(timeUntilNextUpdate),
|
||||||
|
|
|
||||||
|
|
@ -154,9 +154,17 @@ std::shared_ptr<Placefile::Font> Placefile::font(std::size_t i)
|
||||||
|
|
||||||
std::shared_ptr<Placefile> Placefile::Load(const std::string& filename)
|
std::shared_ptr<Placefile> Placefile::Load(const std::string& filename)
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<Placefile> placefile = nullptr;
|
||||||
|
|
||||||
logger_->debug("Loading placefile: {}", filename);
|
logger_->debug("Loading placefile: {}", filename);
|
||||||
std::ifstream f(filename, std::ios_base::in);
|
std::ifstream f(filename, std::ios_base::in);
|
||||||
return Load(filename, f);
|
|
||||||
|
if (f.is_open())
|
||||||
|
{
|
||||||
|
placefile = Load(filename, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return placefile;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Placefile> Placefile::Load(const std::string& name,
|
std::shared_ptr<Placefile> Placefile::Load(const std::string& name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue