Last active
July 8, 2020 16:29
-
-
Save Shadid12/ad73d35341d0e2b0b8bf2e7bdb72b8f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.js | |
const { fork } = require('child_process'); | |
app.get('/endpoint', (request, response) => { | |
// fork another process | |
const process_ml_algo = fork('./process_data.js'); | |
const data = request.body.data; | |
// send send the data to forked process | |
process_ml_algo.send({ data }); | |
// listen to forked process | |
process.on('ml_algo', (result) => { | |
log.info(`ml_algo executed with ${result}`); | |
}); | |
return response.json({ status: true, sent: true }); | |
}); | |
// process_data.js | |
// receive message from master process | |
process.on('ml_algo', async (message) => { | |
const result = await runMachineLearningProcess(message.mails); | |
// send response to master process | |
process.send({ result: result }); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment