Move more crap to the base class

This commit is contained in:
King_DuckZ 2020-08-10 18:52:40 +01:00
parent c1e21bb8d6
commit 4b3d88b2f0
5 changed files with 13 additions and 21 deletions

View file

@ -17,7 +17,9 @@
#include "timer_base.hpp" #include "timer_base.hpp"
#include "roar11/ThreadPool.hpp" #include "roar11/ThreadPool.hpp"
#include "oro/api.hpp"
#include <cassert> #include <cassert>
#include <iostream>
namespace duck { namespace duck {
@ -41,6 +43,12 @@ void TimerBase::on_timer() {
m_pool->submit(&TimerBase::fetch_data, this); m_pool->submit(&TimerBase::fetch_data, this);
} }
void TimerBase::set_next_timer (const oro::Header& header) {
const int next_timer = header.retry_after / header.rate_limit;
std::cout << "Next timer in " << next_timer << " secs\n";
this->set_timer(static_cast<double>(next_timer));
}
roar11::ThreadPool& TimerBase::pool() { roar11::ThreadPool& TimerBase::pool() {
assert(m_pool); assert(m_pool);
return *m_pool; return *m_pool;

View file

@ -27,6 +27,7 @@ namespace roar11 {
namespace oro { namespace oro {
class Api; class Api;
class OriginsDB; class OriginsDB;
struct Header;
} //namespace oro } //namespace oro
namespace duck { namespace duck {
@ -45,6 +46,7 @@ public:
virtual void on_timer() override; virtual void on_timer() override;
protected: protected:
void set_next_timer (const oro::Header& header);
roar11::ThreadPool& pool(); roar11::ThreadPool& pool();
oro::Api& oro_api(); oro::Api& oro_api();
oro::OriginsDB& db(); oro::OriginsDB& db();

View file

@ -34,13 +34,7 @@ namespace duck {
void TimerIcons::fetch_data() { void TimerIcons::fetch_data() {
auto icons = oro_api().items_icons(); auto icons = oro_api().items_icons();
set_next_timer(icons.first);
{
const int next_timer = icons.first.retry_after / icons.first.rate_limit;
std::cout << "Next timer in " << next_timer << " secs\n";
set_timer(static_cast<double>(next_timer));
}
db().update(icons.second); db().update(icons.second);
} }

View file

@ -34,13 +34,7 @@ namespace duck {
void TimerItems::fetch_data() { void TimerItems::fetch_data() {
auto items = oro_api().items_list(); auto items = oro_api().items_list();
set_next_timer(items.first);
{
const int next_timer = items.first.retry_after / items.first.rate_limit;
std::cout << "Next timer in " << next_timer << " secs\n";
set_timer(static_cast<double>(next_timer));
}
db().update(items.second); db().update(items.second);
} }

View file

@ -34,13 +34,7 @@ namespace duck {
void TimerShops::fetch_data() { void TimerShops::fetch_data() {
auto shops = oro_api().market_list(); auto shops = oro_api().market_list();
set_next_timer(shops.first);
{
const int next_timer = shops.first.retry_after / shops.first.rate_limit;
std::cout << "Next timer in " << next_timer << " secs\n";
set_timer(static_cast<double>(next_timer));
}
db().update(shops.second); db().update(shops.second);
} }