Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes publisher list re-try logic #1906

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retry timer was reduced to 1-5min as it's really important to get this list asap. Endpoint is behind CDN so we should be good here


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