From baf0256f840ab395d5476b773d47e52f852dbe93 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 5 Sep 2020 02:14:42 +0100 Subject: [PATCH] Store next access time in the db when server returns 429 --- src/oro/originsdb.hpp | 1 + src/oro/private/originsdb_sqlite.cpp | 4 ++++ src/oro/private/originsdb_sqlite.hpp | 1 + src/timer_base.cpp | 8 ++++++++ src/timer_base.hpp | 1 + src/timer_oro_api.cpp | 1 + 6 files changed, 16 insertions(+) diff --git a/src/oro/originsdb.hpp b/src/oro/originsdb.hpp index 7aa9c70..6517edf 100644 --- a/src/oro/originsdb.hpp +++ b/src/oro/originsdb.hpp @@ -40,6 +40,7 @@ public: virtual void update (const Creators& creat, const oro::Timestamp& next_update, const Source& source) = 0; virtual Timestamp next_access_time (DBOperation op) const = 0; + virtual void update_access_time (const oro::Timestamp& next_update, DBOperation op) = 0; static std::unique_ptr make (std::string_view name, std::string_view param); }; diff --git a/src/oro/private/originsdb_sqlite.cpp b/src/oro/private/originsdb_sqlite.cpp index b17216d..de1db54 100644 --- a/src/oro/private/originsdb_sqlite.cpp +++ b/src/oro/private/originsdb_sqlite.cpp @@ -585,6 +585,10 @@ Timestamp OriginsDBSQLite::next_access_time (DBOperation op) const { return from_sqlite_timestamp(std::move(*info)); } +void OriginsDBSQLite::update_access_time (const oro::Timestamp& next_update, DBOperation op) { + update_last_access(*m_db, op, next_update); +} + } //namespace oro #endif diff --git a/src/oro/private/originsdb_sqlite.hpp b/src/oro/private/originsdb_sqlite.hpp index 2bc88f0..ed21d48 100644 --- a/src/oro/private/originsdb_sqlite.hpp +++ b/src/oro/private/originsdb_sqlite.hpp @@ -40,6 +40,7 @@ public: void update (const Creators& creat, const oro::Timestamp& next_update, const Source& source) override; Timestamp next_access_time (DBOperation op) const override; + void update_access_time (const oro::Timestamp& next_update, DBOperation op) override; private: std::string m_path; diff --git a/src/timer_base.cpp b/src/timer_base.cpp index 27db452..d29dd6f 100644 --- a/src/timer_base.cpp +++ b/src/timer_base.cpp @@ -97,6 +97,14 @@ oro::OriginsDB& TimerBase::db() { return *m_db; } +void TimerBase::reset_db_access_time (oro::DBOperation op) { + oro::Timestamp ts; + ts.ts = + std::chrono::time_point_cast(std::chrono::system_clock::now()) + + std::chrono::seconds(static_cast(m_min_wait)); + db().update_access_time(ts, op); +} + void TimerBase::update_db (const oro::Shops& shops, const oro::Header& header, const oro::Source& source) { db().update(shops, calc_next_update(header, m_min_wait, m_extra_delay), source); } diff --git a/src/timer_base.hpp b/src/timer_base.hpp index f174a93..3ea75ee 100644 --- a/src/timer_base.hpp +++ b/src/timer_base.hpp @@ -73,6 +73,7 @@ protected: roar11::ThreadPool& pool(); oro::Api& oro_api(); oro::OriginsDB& db(); + void reset_db_access_time (oro::DBOperation op); private: virtual void fetch_data(bool with_raw) = 0; diff --git a/src/timer_oro_api.cpp b/src/timer_oro_api.cpp index cda1c8b..45e4a75 100644 --- a/src/timer_oro_api.cpp +++ b/src/timer_oro_api.cpp @@ -111,6 +111,7 @@ inline void TimerOroApi::fetch_data (bool with_raw) { head.retry_after = 600; std::string server = "forged_header"; set_next_timer(head); + this->reset_db_access_time(Op); } }