Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

npm cron blocking Express.JS HTTP requests

$
0
0

I'm trying the cron module from npm in my Express.js application.

The app structure is pretty simple, I have a function to connect to the database, and in there I register all the various modules which handle HTTP requests, something like this:

import { Router } from 'express';
export default ({ config }) => {
    let api = Router();

    connectAllDbs(config, ({mysql}) => {

        userModule({api, config, mysql});
        // other modules...
    });

    return api;
};

Now I've written a cron and added it after those HTTP modules are loaded, as it also depends on a database connection

const cron = new CronJob('* */30 * * *', () => {
    // do stuff w/ mysql
});
cron.start();

With this addition some of the HTTP requests to the node server are randomly 'pending' in the browser

pending http request

I've started reading up on child processes and worker threads, but these seem arduous as the external file is now outside of my nice babel-enabled codebase, so I have to figure out some voodoo in package.json to get a script outside of index.js to flow through all of that...

Is this expected behavior with the cron module? I didn't see anything on the README or known issues; I'm surprised nobody else has encountered this, which makes me think I'm doing something wrong - any idea what that might be?


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>