Store next access time in the db when server returns 429

This commit is contained in:
King_DuckZ 2020-09-05 02:14:42 +01:00
parent e24ebcf8e8
commit baf0256f84
6 changed files with 16 additions and 0 deletions

View file

@ -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<OriginsDB> make (std::string_view name, std::string_view param);
};

View file

@ -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

View file

@ -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;

View file

@ -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<oro::timestamp_t::duration>(std::chrono::system_clock::now()) +
std::chrono::seconds(static_cast<unsigned long>(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);
}

View file

@ -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;

View file

@ -111,6 +111,7 @@ inline void TimerOroApi<Op>::fetch_data (bool with_raw) {
head.retry_after = 600;
std::string server = "forged_header";
set_next_timer(head);
this->reset_db_access_time(Op);
}
}