Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Defaults log parser interval to 60 seconds
Browse files Browse the repository at this point in the history
5 seconds was causing issues in some windows machines
Starts log parsers evenly
  • Loading branch information
gilnobrega committed Jan 11, 2022
1 parent 6237989 commit f1dd829
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion blockchain/xch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"daemon": 55400
},
"Report Interval": 600,
"Log Parse Interval": 5
"Log Parse Interval": 60
}
4 changes: 2 additions & 2 deletions docs/forks.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ In the event that your coin is not listed here, you will need to create a templa
"daemon": 55400
},
"Report Interval": 600,
"Log Parse Interval": 5
"Log Parse Interval": 60
}
```

Expand Down Expand Up @@ -99,4 +99,4 @@ RPC Service Ports
### Log Parse Interval
OPTIONAL: Interval between debug.log lookups (in seconds).

Defaults to 5 seconds.
Defaults to 60 seconds.
2 changes: 1 addition & 1 deletion environment_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ environment_config:
fields: # set of fields for command
version: # key name
const: true # optional, default to TRUE
default: 1.8.1.1 # optional, default value for key, if not provided key will be required during command run
default: 1.8.1.2 # optional, default value for key, if not provided key will be required during command run
dotenv: true # optional, default to FALSE, if this field should be added to .env file

50 changes: 35 additions & 15 deletions farmr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ bool firstTime = true;

late dartconsole.Console console;
Future<void> reportSelector() async {
print("""\nfarmr sends a report every 10 minutes.
print(
"""\nfarmr sends a report every 10 minutes.
Do not close this window or these stats will not show up in farmr.net and farmrBot
""");

Expand Down Expand Up @@ -269,10 +270,10 @@ Do not close this window or these stats will not show up in farmr.net and farmrB
} catch (error) {}
}

void timeoutIsolate(SendPort timeoutPort) {
Future<void> timeoutIsolate(SendPort timeoutPort) async {
final int timeOutMins = reportIntervalDuration.inMinutes * 2;

io.sleep(Duration(minutes: timeOutMins));
await Future.delayed(Duration(minutes: timeOutMins));

timeoutPort.send("timeout");
}
Expand All @@ -290,37 +291,51 @@ void spawnBlokchains(List<Object> arguments) async {

int counter = 0;

final int delayBetweenInMilliseconds =
final int reportDelayBetweenInMilliseconds =
(reportIntervalDuration.inMilliseconds / blockchains.length).round();

//log parser isolate
for (Blockchain blockchain in blockchains) {
if (!blockchain.config.parseLogs) continue;

//Starts log parsers for each blockchain evenly
final int index = blockchains.indexOf(blockchain);

final int loggerDelayInMilliseconds =
((blockchain.logParsingIntervalDuration.inMilliseconds /
blockchains.length)
.round() *
index);

//starts isolate for log parsing
final loggerReceivePort = ReceivePort();
final loggerIsolate = await Isolate.spawn(
final logParserReceivePort = ReceivePort();
final logParserIsolate = await Isolate.spawn(
startLogParsing,
[loggerReceivePort.sendPort, blockchain, onetime],
[
logParserReceivePort.sendPort,
blockchain,
onetime,
loggerDelayInMilliseconds
],
);

log.warning(
"${blockchain.currencySymbol.toUpperCase()}: starting log parser...");

loggerReceivePort.listen((message) {
logParserReceivePort.listen((message) {
if (message is String) {
log.warning(message);

if (message.contains("stopped")) {
blockchain.completedFirstLogParse = true;

loggerReceivePort.close();
loggerIsolate.kill();
logParserReceivePort.close();
logParserIsolate.kill();
} else if (message.contains("not found")) {
blockchain.config.parseLogs = false;

loggerReceivePort.close();
loggerIsolate.kill();
logParserReceivePort.close();
logParserIsolate.kill();
}
} else if (message is List<Object>) {
blockchain.log.filters = message[0] as List<Filter>;
Expand Down Expand Up @@ -359,7 +374,7 @@ void spawnBlokchains(List<Object> arguments) async {

//evenly distributes blockchains
final int blockchainDelay =
(counter > 1) ? i * delayBetweenInMilliseconds : 0;
(counter > 1) ? i * reportDelayBetweenInMilliseconds : 0;

final reporterReceivePort = ReceivePort();
final reporterIsolate = await Isolate.spawn(
Expand All @@ -384,7 +399,8 @@ void spawnBlokchains(List<Object> arguments) async {
sendPort.send({
"${blockchain.currencySymbol.toUpperCase()} - View report":
(message as List<String>)[0],
"${blockchain.currencySymbol.toUpperCase()} - View addresses": """
"${blockchain.currencySymbol.toUpperCase()} - View addresses":
"""
Farmer Reward Address: ${message[3]}
Pool Reward Address: ${message[4]}
Expand Down Expand Up @@ -421,6 +437,9 @@ void startLogParsing(List<Object> arguments) async {
SendPort sendPort = arguments[0] as SendPort;
Blockchain blockchain = arguments[1] as Blockchain;
bool onetime = arguments[2] as bool;
int logParserDelay = arguments[3] as int;

await Future.delayed(Duration(milliseconds: logParserDelay));

await blockchain.log
.initLogParsing(blockchain.config.parseLogs, onetime, sendPort);
Expand Down Expand Up @@ -729,7 +748,8 @@ Future<void> checkIfLinked(
String farmerRewardAddress,
String poolRewardAddress) async {
if (response.trim().contains("Not linked")) {
final errorString = """\n\nID $id is not linked to an account.
final errorString =
"""\n\nID $id is not linked to an account.
Link it in farmr.net or through farmrbot and then start this program again
Press enter to quit""";
print(errorString);
Expand Down
4 changes: 2 additions & 2 deletions lib/blockchain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Blockchain {
int get reportInterval => reportInterval;
Duration get reportIntervalDuration => Duration(seconds: _reportInterval);

int _logParseInterval = 5;
int _logParseInterval = 60;
int get logParseInterval => reportInterval;
Duration get logParsingIntervalDuration =>
Duration(seconds: _logParseInterval);
Expand Down Expand Up @@ -149,7 +149,7 @@ class Blockchain {
_majorToMinorMultiplier = json['Major to Minor Multiplier'] ?? 1e12;
_checkPlotSize = json['Check for Complete Plots'] ?? true;
_reportInterval = json['Report Interval'] ?? 600;
_logParseInterval = json['Log Parse Interval'] ?? 5;
_logParseInterval = json['Log Parse Interval'] ?? 60;
}

//sets limits of report interval
Expand Down

0 comments on commit f1dd829

Please sign in to comment.