Meteor.setInterval(Meteor.bindEnvironment(ThisTry()), 5000);
function ThisTry() {
let start = new moment();
start.subtract(30, 'minute'); // pick up stragglers, if any
let end = new moment();
end.add(3, 'minute');
let start1 = start.toDate();
let end1 = end.toDate();
let sendQue = QueueItems.find({
sent: false,
"library_item.shareType": 'tweet',
dateTime: {$gte: start1, $lt: end1}});
console.log("Count to send: " + sendQue.count());
}
Runs once, correct output then:
I20161002-17:02:49.238(-4)? Exception in callback of async function: TypeError: Cannot read property ‘apply’ of undefined
I20161002-17:02:49.238(-4)? at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1)
I20161002-17:02:49.238(-4)? at packages/meteor/dynamics_nodejs.js:123:1
I20161002-17:02:49.238(-4)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20161002-17:02:49.238(-4)? at packages/meteor/timers.js:6:1
- Tried a cron job…
const CronJob = Npm.require('cron').CronJob;
new CronJob('0 */1 * * * *', function() { // change 1 to 5
console.log('Cron Run...');
let sendQue = QueueItems.find({});
console.log(sendQue.count());
}, null, true, 'America/New_York');
Get no results and this error:
I20161002-17:10:00.981(-4)? Cron Run…
W20161002-17:10:01.085(-4)? (STDERR) C:\Users\Greg\WebstormProjects\Saturn_V2.meteor\local\build\programs\server\packages\meteor.js:1060
W20161002-17:10:01.085(-4)? (STDERR) throw new Error("Meteor code must always run within a Fiber. " +
W20161002-17:10:01.085(-4)? (STDERR) ^
W20161002-17:10:01.086(-4)? (STDERR)
W20161002-17:10:01.086(-4)? (STDERR) Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
W20161002-17:10:01.088(-4)? (STDERR) at Object.Meteor.nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9:1)
W20161002-17:10:01.088(-4)? (STDERR) at [object Object]..extend.get (packages/meteor/dynamics_nodejs.js:21:1)
W20161002-17:10:01.088(-4)? (STDERR) at Object.collection.(anonymous function) [as find] (packages/matb33_collection-hooks/packages/matb33_collection-hooks.js:107:1)
W20161002-17:10:01.088(-4)? (STDERR) at [object Object].find (packages/mongo/collection.js:315:29)
W20161002-17:10:01.088(-4)? (STDERR) at CronJob. (server/autosharing/every5.ts:13:30)
W20161002-17:10:01.088(-4)? (STDERR) at CronJob.fireOnTick (C:\Users\Greg\WebstormProjects\Saturn_V2\node_modules\cron\lib\cron.js:392:22)
W20161002-17:10:01.088(-4)? (STDERR) at [object Object].callbackWrapper [as _onTimeout] (C:\Users\Greg\WebstormProjects\Saturn_V2\node_modules\cron\lib\cron.js:435:9)
W20161002-17:10:01.088(-4)? (STDERR) at Timer.listOnTimeout (timers.js:92:15)
I have not written my async function yet…
At a loss of how to even access the database it seems on the server (in the /server path )at intervals.