I am trying to do something which i thought would have been very trivial, but apparently is not. I need to do something very simple, I need to run a setInterval so to check whether "today" is a new day, and if it is a new day, get some data and send an email.
Everytime i try, it returns me the usual issue Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment. The code is running on Meteor server in a Meteor startup function. All help will be greatly appreciated, i tried to solve it with async, fibers and future and i am either doing it wrong or i haven't found the answer yet. Thank you, Alessio
setInterval(function(){
var now = moment().format('L');
var date1 = new Date(now);
var date2 = new Date(yesterday);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
if(diffDays>0){
yesterday=now;
//this is the part giving me problems
Email.send({
to: 'alexbonti83@hotmail.com',
from: 'alexbonti83@hotmail.com',
subject: 'test',
text: 'test'
});
}else{
// console.log('is the same day');
}
},delay);