Nguyen Hoang Vu
Nguyen Hoang Vu

Reputation: 853

Node-Schedule run on different processes

I'm using node-schedule for doing cron job with nodejs. This is my code:

import '../config';
import schedule from 'node-schedule';

import { startAssignment, closeAssignment } from '../course/schedule';

schedule.scheduleJob('*/1 * * * *', startAssignment);
schedule.scheduleJob('*/1 * * * *', closeAssignment);

I wonder if two scheduled jobs run on different processes or the same? I try to view on Linux using

sudo ps -aux

and it give this:

22032 0.0 0.0 4632 864 pts/2 S+ 17:47 0:00 /bin/sh -c NODE_PATH=. babel-node app/schedule/index.js

which mean it is running on the same process. So is there any way to make them run on different process with different pid?

Why I need them to run on diffeent processes with different pids? Because when a process start, I want to check if there is a similar process running with the same pid, so I stop them to prevent duplicate processes which may take too much resource of the server.

Thank you. I appreciate any type of documents.

Upvotes: 0

Views: 2302

Answers (1)

Ankit Kumar Rajpoot
Ankit Kumar Rajpoot

Reputation: 5590

You can use a fork for multiple processes in the node.

const { fork } = require('child_process');

https://itnext.io/multi-threading-and-multi-process-in-node-js-ffa5bb5cde98

Upvotes: 1

Related Questions