I'm experimenting with the cron module from npm within my Express.js application.
The structure of my app is quite straightforward. I have a function to establish a connection to the database, where I then register all the different modules that handle HTTP requests. Here is an example:
import { Router } from 'express';
export default ({ config }) => {
let api = Router();
connectAllDbs(config, ({mysql}) => {
userModule({api, config, mysql});
// other modules...
});
return api;
};
After loading these HTTP modules, I added a cron job which relies on a database connection as well:
const cron = new CronJob('* */30 * * *', () => {
// perform actions with mysql
});
cron.start();
Since adding the cron job, some of the HTTP requests sent to the node server are intermittently stuck in a 'pending' state in the browser.
https://i.sstatic.net/YFpIB.png
In response to this issue, I began researching child processes and worker threads. However, integrating these features seems complex since the external file now exists outside of my babel-enabled codebase. This requires additional configurations in package.json to incorporate a script beyond index.js...
Is this behavior typical when using the cron module? Despite checking the README and known issues list, it appears no one else has reported similar problems. This leads me to believe I might be overlooking something - any insights on what that could be?