Skip to content

Commit

Permalink
Fixes publisher list re-try logic
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Mar 26, 2019
1 parent 596d189 commit 8111380
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ void LedgerImpl::OnPublisherListLoaded(ledger::Result result,
"Successfully loaded but failed to parse publish list.";
BLOG(this, ledger::LogLevel::LOG_DEBUG) <<
"Failed publisher list: " << data;
RefreshPublishersList(true);
return;
} else {
// List was loaded successfully
RefreshPublishersList(false);
return;
}
} else {
BLOG(this, ledger::LogLevel::LOG_ERROR) <<
Expand All @@ -317,7 +323,7 @@ void LedgerImpl::OnPublisherListLoaded(ledger::Result result,
"Failed publisher list: " << data;
}

RefreshPublishersList(false);
RefreshPublishersList(true, true);
}

std::string LedgerImpl::GenerateGUID() const {
Expand Down Expand Up @@ -803,23 +809,27 @@ void LedgerImpl::LoadPublishersListCallback(
}
}

void LedgerImpl::RefreshPublishersList(bool retryAfterError) {
void LedgerImpl::RefreshPublishersList(bool retryAfterError, bool immediately) {
uint64_t start_timer_in{ 0ull };

if (last_pub_load_timer_id_ != 0) {
// timer in progress
return;
}

if (retryAfterError) {
start_timer_in = retryRequestSetup(300, 3600);
uint64_t lastLoadTimestamp =
bat_publishers_->getLastPublishersListLoadTimestamp();

if (immediately) {
start_timer_in = 0ull;
} else if (retryAfterError) {
start_timer_in = retryRequestSetup(60, 300);

BLOG(this, ledger::LogLevel::LOG_WARNING) <<
"Failed to refresh publishesr list, will try again in " << start_timer_in;
"Failed to refresh publishesr list, will try again in " <<
start_timer_in << " seconds.";
} else {
uint64_t now = std::time(nullptr);
uint64_t lastLoadTimestamp =
bat_publishers_->getLastPublishersListLoadTimestamp();

// check if lastLoadTimestamp doesn't exist or have erroneous value.
// (start_timer_in == 0) is expected to call callback function immediately.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class LedgerImpl : public ledger::Ledger,
void OnLedgerStateLoaded(ledger::Result result,
const std::string& data) override;

void RefreshPublishersList(bool retryAfterError);
void RefreshPublishersList(bool retryAfterError, bool immediately = false);

void RefreshGrant(bool retryAfterError);

Expand Down

0 comments on commit 8111380

Please sign in to comment.