11/* eslint-disable no-restricted-syntax */
2- // const { Pull, Push } = require('zeromq');
32const fs = require ( 'fs' ) ;
43const Bugout = require ( 'bugout' ) ;
54const events = require ( 'events' ) ;
@@ -10,7 +9,7 @@ const Crypt = require('./Crypt');
109const { Helper } = require ( './Helper' ) ;
1110require ( 'dotenv' ) . config ( ) ;
1211
13- const minRequestWorkWindow = 60 ;
12+ const minRequestWorkWindow = 15 ; // seconds
1413
1514class Worker {
1615 constructor ( { token, name = 'no_name' , loglevel, transferEncryptToken = null } = { } ) {
@@ -61,7 +60,12 @@ class Worker {
6160 this . log . info ( 'Announcing to trackers...' ) ;
6261 this . event . addListener ( 'requestWork' , this . requestWork ) ;
6362 this . event . addListener ( 'shareResults' , this . shareResults ) ;
64- setInterval ( this . requestWork , 10000 ) ;
63+ setInterval ( ( ) => {
64+ // prevent unnecessary requests , flooding Master
65+ if ( Helper . getTimestamp ( ) - this . lastRequestWork > minRequestWorkWindow * 1000 ) {
66+ this . event . emit ( 'requestWork' ) ;
67+ }
68+ } , 30000 ) ;
6569 this . registerRPC ( ) ;
6670 this . crypt = new Crypt ( transferEncryptToken || process . env . transferEncryptToken ) ;
6771 if ( this . crypt . key instanceof Error ) {
@@ -83,7 +87,7 @@ class Worker {
8387 ) ;
8488 }
8589
86- async requestWork ( ) {
90+ requestWork ( ) {
8791 if ( ! this . MasterAdress ) {
8892 this . log . warn ( 'Cant requestWork from Master if his address not discovered yet' ) ;
8993 return ;
@@ -172,7 +176,7 @@ class Worker {
172176 this . checkCurrentAssets ( ) ;
173177 this . working = false ;
174178 this . event . emit ( 'requestWork' ) ;
175- }
179+ } else if ( answer . status === 'same' && ! this . working ) this . event . emit ( 'requestWork' ) ;
176180 //
177181 this . log . debug ( 'requestExecAssets answer:' , answer ) ;
178182 } ) ;
0 commit comments