evilhei
1
Hi,
I’m trying to run cron job but I keep getting error:
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
What I’m doing wrong? It looks like I am binding the Meteor.call?
import { Meteor } from 'meteor/meteor';
var CronJob = require('cron').CronJob;
console.log('Befire job instantiation');
const ExchangeRateSyncJob = new CronJob('0 */1 * * * *', function() {
Meteor.bindEnvironment(Meteor.call('ExchangeRateSync.create'))
});
console.log('After job instantiation');
ExchangeRateSyncJob.start();
rjdavid
2
What you need to bind is the callback function i.e. the callback when creating a new CronJob
You could also look at some atmosphere packages for cron jobs.
Ones that spring to mind:
Its this part:
const ExchangeRateSyncJob = new CronJob('0 */1 * * * *', function() {
Meteor.bindEnvironment(Meteor.call('ExchangeRateSync.create'))
});
Try this:
const ExchangeRateSyncJob = new CronJob('0 */1 * * * *', Meteor.bindEnvironment(function() {
Meteor.call('ExchangeRateSync.create')
}));
evilhei
5
Thank you, worked very well