No Mongo Query gets result when cron is running in background

I was NodeJS as server side and MongoDB as our database. This works really well.

Now I have added a library to our system node-schedule

to call the function as a cron-job.

The process takes about an hour.

My problem is whenever cron is running, all users on my site get No response fro server. The ie database is locked.

Stuck with an issue for a week, needs a good solution to run cron without affecting users using the site.

+3


source to share


1 answer


Typically you want to write a worker and run the worker at a different entry point that is not part of your server. There are several ways to accomplish this.

1) Write to a worker on another server to interact with your database

2) Write a service worker on another server that communicates with your api



3) Use the same server, but set up a cronjob to execute a file that does the job at the specified time.

But you shouldn't be doing this from the same entry point as your server. You need a different execution file.

There is one thing you can do to get it running when it is not sick on your server, and that will be for your node -schedule trigger to start the child process. https://nodejs.org/api/child_process.html

0


source







All Articles