From f1dd8297931a0f15b85849d392f2c78036f17e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gil=20N=C3=B3brega?= Date: Tue, 11 Jan 2022 22:57:51 +0000 Subject: [PATCH] Defaults log parser interval to 60 seconds 5 seconds was causing issues in some windows machines Starts log parsers evenly --- blockchain/xch.json | 2 +- docs/forks.md | 4 ++-- environment_config.yaml | 2 +- farmr.dart | 50 ++++++++++++++++++++++++++++------------- lib/blockchain.dart | 4 ++-- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/blockchain/xch.json b/blockchain/xch.json index e621788..5b21f73 100644 --- a/blockchain/xch.json +++ b/blockchain/xch.json @@ -15,5 +15,5 @@ "daemon": 55400 }, "Report Interval": 600, - "Log Parse Interval": 5 + "Log Parse Interval": 60 } \ No newline at end of file diff --git a/docs/forks.md b/docs/forks.md index f60b582..d5038e4 100644 --- a/docs/forks.md +++ b/docs/forks.md @@ -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 } ``` @@ -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. diff --git a/environment_config.yaml b/environment_config.yaml index 9497723..47a952a 100644 --- a/environment_config.yaml +++ b/environment_config.yaml @@ -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 diff --git a/farmr.dart b/farmr.dart index 8221759..2240ec4 100644 --- a/farmr.dart +++ b/farmr.dart @@ -235,7 +235,8 @@ bool firstTime = true; late dartconsole.Console console; Future 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 """); @@ -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 timeoutIsolate(SendPort timeoutPort) async { final int timeOutMins = reportIntervalDuration.inMinutes * 2; - io.sleep(Duration(minutes: timeOutMins)); + await Future.delayed(Duration(minutes: timeOutMins)); timeoutPort.send("timeout"); } @@ -290,37 +291,51 @@ void spawnBlokchains(List 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) { blockchain.log.filters = message[0] as List; @@ -359,7 +374,7 @@ void spawnBlokchains(List 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( @@ -384,7 +399,8 @@ void spawnBlokchains(List arguments) async { sendPort.send({ "${blockchain.currencySymbol.toUpperCase()} - View report": (message as List)[0], - "${blockchain.currencySymbol.toUpperCase()} - View addresses": """ + "${blockchain.currencySymbol.toUpperCase()} - View addresses": + """ Farmer Reward Address: ${message[3]} Pool Reward Address: ${message[4]} @@ -421,6 +437,9 @@ void startLogParsing(List 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); @@ -729,7 +748,8 @@ Future 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); diff --git a/lib/blockchain.dart b/lib/blockchain.dart index 073e09a..6344755 100644 --- a/lib/blockchain.dart +++ b/lib/blockchain.dart @@ -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); @@ -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