Skip to content

Commit 0b8225b

Browse files
committed
read params from task input
1 parent 7f7b8b2 commit 0b8225b

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ To install or update LODA, please follow the [installation instructions](https:/
22

33
## [Unreleased]
44

5+
# v22.7.26
6+
57
### Bugfixes
68

79
* Fix CPU hour reporting using `wget`
810

911
### Features
1012

1113
* Embedded `git` for BOINC on Windows
14+
* Read parameters from BOINC task input
1215

1316
### Enhancements
1417

src/boinc.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void Boinc::run() {
3333

3434
// log debugging info
3535
Log::get().info("Platform: " + Version::PLATFORM +
36-
", user name: " + user_name + ", hostid: " + hostid);
36+
", user name: " + user_name + ", host ID: " + hostid);
3737

3838
// initialize setup
3939
Setup::setLodaHome(project_dir);
@@ -58,8 +58,36 @@ void Boinc::run() {
5858
}
5959
#endif
6060

61-
// pick a random miner profile if not mining in parallel
62-
if (!settings.parallel_mining || settings.num_miner_instances == 1) {
61+
// read input data
62+
auto input_str = getFileAsString(slot_dir + "input");
63+
if (!input_str.empty() && input_str[0] == '{') {
64+
auto input = jute::parser::parse(input_str);
65+
66+
auto minSequenceTerms = input["minSequenceTerms"];
67+
if (minSequenceTerms.get_type() == jute::JNUMBER) {
68+
settings.num_terms = minSequenceTerms.as_int();
69+
Log::get().info("Setting minimum sequence terms to " +
70+
std::to_string(settings.num_terms));
71+
}
72+
73+
auto maxCycles = input["maxCycles"];
74+
if (maxCycles.get_type() == jute::JNUMBER) {
75+
settings.max_cycles = maxCycles.as_int();
76+
Log::get().info("Setting maximum cycles to " +
77+
std::to_string(settings.max_cycles));
78+
}
79+
80+
auto minerProfile = input["minerProfile"];
81+
if (minerProfile.get_type() == jute::JSTRING) {
82+
settings.miner_profile = minerProfile.as_string();
83+
Log::get().info("Setting miner profile to \"" + settings.miner_profile +
84+
"\"");
85+
}
86+
}
87+
88+
// pick a random miner profile if not set already
89+
if ((!settings.parallel_mining || settings.num_miner_instances == 1) &&
90+
settings.miner_profile.empty()) {
6391
settings.miner_profile = std::to_string(Random::get().gen() % 100);
6492
}
6593

src/file.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ std::string getNullRedirect() {
295295
#endif
296296
}
297297

298-
std::string getFileAsString(const std::string &filename) {
298+
std::string getFileAsString(const std::string &filename, bool fail_on_error) {
299299
std::ifstream in(filename);
300300
std::string str;
301301
if (in.good()) {
@@ -306,7 +306,7 @@ std::string getFileAsString(const std::string &filename) {
306306
in.close();
307307
}
308308
if (str.empty()) {
309-
Log::get().error("Error loading " + filename, true);
309+
Log::get().error("Error loading " + filename, fail_on_error);
310310
}
311311
return str;
312312
}

src/include/file.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ std::string getBashRc();
4747

4848
std::string getNullRedirect();
4949

50-
std::string getFileAsString(const std::string &filename);
50+
std::string getFileAsString(const std::string &filename,
51+
bool fail_on_error = true);
5152

5253
int64_t getFileAgeInDays(const std::string &path);
5354

0 commit comments

Comments
 (0)