I have this piece of code:
Meteor.methods({
GetTickerInfo: function(){
Future = Npm.require('fibers/future');
var myFuture = new Future();
kraken.api('Ticker', {"pair": 'ETHXBT'}, function(error, data) {
if(error) {
console.log(error);
}
else {
console.log(data.result);
console.log(data.result.XETHXXBT.a);
myFuture.return(data.result);
}
});
console.log("EHEHEHEHEHHEEH");
console.log(myFuture.wait());
return myFuture.wait();
}
});
What it does it calls an API, gets some data back and when it's done it returns the data to the client so I can visualise in the graph. For now its a MANUAL click button on the client side which calls the method, does the job, and returns the data.
I would like to schedule a cron to do that. So every 5 sec make a API call and return the data back to the client (because there is where I visualise it). All the cron jobs are working with specific functions but I can't access the this function GetTickerInfo because it is defined and in the scope of Meteor.methods.
How can I call it be a cron job, but also leave the occasional Meteor Call from the client side when I want to manualy refresh in the given moment?
Can anyone show how would they implement this with for eg CRON package: percolatestudio/meteor-synced-cron
You have to be outside of the methods scope and I would personally do:
SyncedCron.add({
name: 'GetTickerInfo cron',
schedule: function(parser) {
return parser.text('every 5 seconds');
},
job: function() {
Meteor.call('GetTickerInfo');
}
});
SyncedCron.start()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.