Move more crap to the base class
This commit is contained in:
parent
c1e21bb8d6
commit
4b3d88b2f0
5 changed files with 13 additions and 21 deletions
|
@ -17,7 +17,9 @@
|
|||
|
||||
#include "timer_base.hpp"
|
||||
#include "roar11/ThreadPool.hpp"
|
||||
#include "oro/api.hpp"
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
namespace duck {
|
||||
|
||||
|
@ -41,6 +43,12 @@ void TimerBase::on_timer() {
|
|||
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() {
|
||||
assert(m_pool);
|
||||
return *m_pool;
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace roar11 {
|
|||
namespace oro {
|
||||
class Api;
|
||||
class OriginsDB;
|
||||
struct Header;
|
||||
} //namespace oro
|
||||
|
||||
namespace duck {
|
||||
|
@ -45,6 +46,7 @@ public:
|
|||
virtual void on_timer() override;
|
||||
|
||||
protected:
|
||||
void set_next_timer (const oro::Header& header);
|
||||
roar11::ThreadPool& pool();
|
||||
oro::Api& oro_api();
|
||||
oro::OriginsDB& db();
|
||||
|
|
|
@ -34,13 +34,7 @@ namespace duck {
|
|||
|
||||
void TimerIcons::fetch_data() {
|
||||
auto icons = oro_api().items_icons();
|
||||
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
set_next_timer(icons.first);
|
||||
db().update(icons.second);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,13 +34,7 @@ namespace duck {
|
|||
|
||||
void TimerItems::fetch_data() {
|
||||
auto items = oro_api().items_list();
|
||||
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
set_next_timer(items.first);
|
||||
db().update(items.second);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,13 +34,7 @@ namespace duck {
|
|||
|
||||
void TimerShops::fetch_data() {
|
||||
auto shops = oro_api().market_list();
|
||||
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
set_next_timer(shops.first);
|
||||
db().update(shops.second);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue