File tree Expand file tree Collapse file tree
src/interconnected_node/contribution/mapreduce Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,8 +18,6 @@ export default class MapWorkerJob implements Job {
1818 console . log (
1919 'I am a MapWorker that has received the code:\n' + this . mapFunction
2020 ) ;
21- console . log ( 'executing the received code' ) ;
22- eval ( this . mapFunction ) ;
2321 return new Promise < void > ( ( resolve ) => {
2422 resolve ( ) ;
2523 } ) ;
@@ -30,8 +28,12 @@ export default class MapWorkerJob implements Job {
3028 }
3129
3230 enqueueTask ( task : Task ) : Promise < boolean > {
33- console . log ( 'MAP WORKER RECEIVED MAP TASK' ) ;
3431 return new Promise < boolean > ( ( resolve ) => {
32+ task . execute (
33+ { mapFunction : this . mapFunction } ,
34+ ( ) => console . log ( 'COMPLETED MAP TASK' ) ,
35+ ( ) => console . log ( 'ERROR ON MAP TASK' )
36+ ) ;
3537 resolve ( true ) ;
3638 } ) ;
3739 }
Original file line number Diff line number Diff line change 11import Task from '../../common/Task' ;
22
33export default class MapReduceMapTask implements Task {
4+ private regionId : string ;
5+ private splits : Object [ ] ;
6+
47 constructor ( params : any ) {
5- //TODO implement
8+ this . regionId = params . regionId ;
9+ this . splits = params . splits ;
610 }
711
812 execute (
913 jobParams : any ,
1014 onCompletionCallback : ( ) => void ,
1115 onErrorCallback : ( ) => void
1216 ) : Promise < void > {
13- throw new Error ( 'Method not implemented.' ) ;
17+ const mapFunction = jobParams . mapFunction ;
18+ this . splits . forEach ( ( s ) => eval ( mapFunction ) ( s ) ) ;
19+ onCompletionCallback ( ) ;
20+ return new Promise < void > ( ( resolve ) => resolve ( ) ) ;
1421 }
1522}
You can’t perform that action at this time.
0 commit comments