I am using a CronJob to run a function that includes a mongoose/MongoDB query every 10 seconds. Here's the function and CronJob:var runFunction = function (){console.log("At run function, program uses "+ process.memoryUsage().heapUsed+" bytes of Heap."); var users = require('./models/user'); users.find({'local.isActiveUser': "1"}) .then(docs => {console.log("Looking at docs ");console.log(docs.length); //do more stuff with docs }) }new CronJob('*/10 * * * * *', runFunction , null, true);However, the console is printing "Looking at docs" 4-5 times per function run instead of just once. Can anyone suggest what is going on here?I had tried adding .exec()between the .find()and .then()but was getting some Javascript heap memory overruns (FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory) that removing the .exec() seemed to solve.
Submitted March 04, 2020 at 09:52PM by garson515
No comments:
Post a Comment