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 @@ public: void CancelRefresh(); void ScheduleRefresh(); + void ScheduleRefresh( + const std::chrono::system_clock::duration timeUntilNextUpdate); void Update(); void UpdateAsync(); @@ -150,6 +152,8 @@ public: 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(); + // Update refresh timer + 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(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,