Skip to content

Commit 07c719f

Browse files
authored
remove oeis fall-back option (#148)
1 parent 533e2eb commit 07c719f

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ To install or update LODA, please follow the [installation instructions](https:/
55
### Bugfixes
66

77
* Extend folder locking time out value on Windows
8+
* Remove fall-back download from OEIS
89

910
### Features
1011

@@ -13,7 +14,7 @@ To install or update LODA, please follow the [installation instructions](https:/
1314
### Enhancements
1415

1516
* Change default update interval to 3 days
16-
* Throttle download of OEIS files from API server
17+
* Throttling and exponential backoff for API server downloads
1718

1819
# v22.5.20
1920

src/api_client.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void ApiClient::postCPUHour() {
7272
}
7373
}
7474

75-
bool ApiClient::getOeisFile(const std::string& filename,
75+
void ApiClient::getOeisFile(const std::string& filename,
7676
const std::string& local_path) {
7777
// throttling
7878
if (fetched_oeis_files > 2) {
@@ -91,13 +91,26 @@ bool ApiClient::getOeisFile(const std::string& filename,
9191

9292
// fetch file
9393
const std::string url = BASE_URL + "oeis/" + filename + ".gz";
94-
const bool success = WebClient::get(url, local_path + ".gz", false, false);
94+
bool success = false;
95+
int64_t backoff_delay = OEIS_THROTTLING_SECS;
96+
for (int64_t i = 0; i < 5; i++) {
97+
if (i > 0) {
98+
Log::get().warn("Retrying fetch of " + url);
99+
}
100+
success = WebClient::get(url, local_path + ".gz", false, false);
101+
if (success) {
102+
break;
103+
}
104+
std::this_thread::sleep_for(std::chrono::seconds(backoff_delay));
105+
backoff_delay *= 2;
106+
}
95107
if (success) {
96108
gunzip(local_path + ".gz");
97109
fetched_oeis_files++;
98110
last_oeis_time = std::chrono::steady_clock::now();
111+
} else {
112+
Log::get().error("Error fetching " + url, true);
99113
}
100-
return success;
101114
}
102115

103116
bool ApiClient::getProgram(int64_t index, const std::string& path) {

src/include/api_client.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ApiClient {
1818

1919
void postCPUHour();
2020

21-
bool getOeisFile(const std::string& filename, const std::string& local_path);
21+
void getOeisFile(const std::string& filename, const std::string& local_path);
2222

2323
Program getNextProgram();
2424

src/oeis_manager.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,7 @@ void OeisManager::update() {
325325
std::string cmd, path;
326326
for (auto &file : files) {
327327
path = Setup::getOeisHome() + file;
328-
if (!ApiClient::getDefaultInstance().getOeisFile(file, path)) {
329-
Log::get().warn("Cannot fetch " + file +
330-
".gz from API server, falling back to OEIS");
331-
WebClient::get("https://oeis.org/" + file + ".gz", path + ".gz");
332-
gunzip(path + ".gz");
333-
}
328+
ApiClient::getDefaultInstance().getOeisFile(file, path);
334329
}
335330
// update programs repository using git pull
336331
auto mode = Setup::getMiningMode();

src/oeis_sequence.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,7 @@ Sequence OeisSequence::getTerms(int64_t max_num_terms) const {
211211
big_file.peek() == std::ifstream::traits_type::eof()) {
212212
ensureDir(path);
213213
std::remove(path.c_str());
214-
if (!ApiClient::getDefaultInstance().getOeisFile(id_str("b") + ".txt",
215-
path)) {
216-
Log::get().warn(
217-
"Cannot fetch b-file from API server, falling back to OEIS");
218-
WebClient::get(url_str() + "/" + id_str("b") + ".txt", path);
219-
}
214+
ApiClient::getDefaultInstance().getOeisFile(id_str("b") + ".txt", path);
220215
big = loadBFile(id, terms);
221216
}
222217
}

0 commit comments

Comments
 (0)