@@ -37,6 +37,8 @@ class Worker {
3737 this . taskFile = 'null' ;
3838 this . jobsDone = 0 ;
3939 this . jobsToDo = [ ] ; // push here jobs assigned due working..
40+ this . getBatch = Object . prototype . hasOwnProperty . call ( process . env , 'getBatch' ) ? process . env . getBatch : false
41+ this . batchSize = Object . prototype . hasOwnProperty . call ( process . env , 'batchSize' ) ? process . env . batchSize : 5
4042 this . init = this . init . bind ( this ) ;
4143 this . onSeen = this . onSeen . bind ( this ) ;
4244 this . requestWork = this . requestWork . bind ( this ) ;
@@ -112,8 +114,8 @@ class Worker {
112114 if ( Helper . getTimestamp ( ) - this . lastRequestWork > minRequestWorkWindow ) {
113115 // prevent unnecessary requests , flooding Master
114116 this . lastRequestWork = Helper . getTimestamp ( ) ; // track last request for work..
115- this . peer . rpc ( this . MasterAdress , 'requestWork' , { } , async ( masterAns ) => {
116- if ( masterAns . task ) {
117+ this . peer . rpc ( this . MasterAdress , 'requestWork' , { getBatch : this . getBatch , batchSize : this . batchSize } , async ( masterAns ) => {
118+ if ( masterAns . task ) { // single task
117119 // null if no jobs available
118120 const job = this . crypt . decrypt ( JSON . parse ( masterAns . task ) ) ; // decrypt once incoming job data
119121 const startedOn = Helper . getTimestamp ( ) ;
@@ -126,6 +128,14 @@ class Worker {
126128 this . log . warn ( e . message ) ;
127129 } ) ;
128130 }
131+ if ( masterAns . batchTasks ) { // received batch tasks
132+ masterAns . batchTasks . forEach ( ( encryptedTask ) => {
133+ const job = this . crypt . decrypt ( JSON . parse ( encryptedTask ) ) ;
134+ this . jobsToDo . push ( JSON . parse ( job ) ) // push decrypted job to internal queue
135+ } )
136+ // this.log.fatal(this.jobsToDo)
137+ this . event . emit ( 'requestWork' ) ;
138+ }
129139 } ) ;
130140 }
131141 }
0 commit comments