From 06a2a18c0670944b513f503f7850c39f27ca012c Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Fri, 4 Oct 2024 05:40:00 -0500 Subject: [PATCH 1/2] Automatically refresh placefiles that failed to load --- .../scwx/qt/manager/placefile_manager.cpp | 40 ++++++++++++++++++- wxdata/source/scwx/gr/placefile.cpp | 10 ++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp b/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp index b324fae3..6a0392be 100644 --- a/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp @@ -105,6 +105,8 @@ class PlacefileManager::Impl::PlacefileRecord void CancelRefresh(); void ScheduleRefresh(); + void ScheduleRefresh( + const std::chrono::system_clock::duration timeUntilNextUpdate); void Update(); void UpdateAsync(); @@ -150,6 +152,8 @@ class PlacefileManager::Impl::PlacefileRecord std::string lastRadarSite_ {}; std::chrono::system_clock::time_point lastUpdateTime_ {}; + + std::size_t failureCount_ {}; }; PlacefileManager::PlacefileManager() : p(std::make_unique(this)) @@ -542,6 +546,11 @@ void PlacefileManager::Impl::PlacefileRecord::Update() if (url.isLocalFile()) { updatedPlacefile = gr::Placefile::Load(name); + + if (updatedPlacefile == nullptr) + { + logger_->error("Local placefile not found: {}", name); + } } else { @@ -625,6 +634,7 @@ void PlacefileManager::Impl::PlacefileRecord::Update() placefile_ = updatedPlacefile; title_ = placefile_->title(); lastUpdateTime_ = std::chrono::system_clock::now(); + failureCount_ = 0; // Update font resources { @@ -645,10 +655,30 @@ void PlacefileManager::Impl::PlacefileRecord::Update() // Notify slots of the placefile update Q_EMIT p->self_->PlacefileUpdated(name); } + + // Update refresh timer + ScheduleRefresh(); } + else if (enabled_) + { + using namespace std::chrono_literals; - // Update refresh timer - ScheduleRefresh(); + ++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(15s * failureCount_, 60s)); + } + } } void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh() @@ -666,6 +696,12 @@ void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh() auto nextUpdateTime = lastUpdateTime_ + refresh_time(); auto timeUntilNextUpdate = nextUpdateTime - std::chrono::system_clock::now(); + ScheduleRefresh(timeUntilNextUpdate); +} + +void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh( + const std::chrono::system_clock::duration timeUntilNextUpdate) +{ logger_->debug( "Scheduled refresh in {:%M:%S} ({})", std::chrono::duration_cast(timeUntilNextUpdate), diff --git a/wxdata/source/scwx/gr/placefile.cpp b/wxdata/source/scwx/gr/placefile.cpp index 02bb3527..808ce19c 100644 --- a/wxdata/source/scwx/gr/placefile.cpp +++ b/wxdata/source/scwx/gr/placefile.cpp @@ -154,9 +154,17 @@ std::shared_ptr Placefile::font(std::size_t i) std::shared_ptr Placefile::Load(const std::string& filename) { + std::shared_ptr placefile = nullptr; + logger_->debug("Loading placefile: {}", filename); 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::Load(const std::string& name, From 621cbb3d5169531684efdb8bae5c6f4ab65c3da5 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 5 Oct 2024 04:11:28 -0500 Subject: [PATCH 2/2] Refresh placefiles as often as every 1 second --- scwx-qt/source/scwx/qt/manager/placefile_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp b/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp index 6a0392be..58049fc6 100644 --- a/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp @@ -348,8 +348,8 @@ PlacefileManager::Impl::PlacefileRecord::refresh_time() const if (refresh_enabled()) { - // Don't refresh more often than every 15 seconds - return std::max(placefile_->refresh(), 15s); + // Don't refresh more often than every 1 second + return std::max(placefile_->refresh(), 1s); } return -1s;