Skip to content

Instantly share code, notes, and snippets.

@Shadid12
Last active July 8, 2020 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shadid12/ad73d35341d0e2b0b8bf2e7bdb72b8f0 to your computer and use it in GitHub Desktop.
Save Shadid12/ad73d35341d0e2b0b8bf2e7bdb72b8f0 to your computer and use it in GitHub Desktop.
// 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