[英]Setting a cron job for a Meteor Method
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. 它所谓的API,获取一些数据,完成后将数据返回给客户端,这样我就可以在图形中可视化。 For now its a MANUAL click button on the client side which calls the method, does the job, and returns the data. 现在,它是客户端上的MANUAL单击按钮,它调用方法,执行工作并返回数据。
I would like to schedule a cron to do that. 我想安排一个cron来做到这一点。 So every 5 sec make a API call and return the data back to the client (because there is where I visualise it). 因此,每5秒钟进行一次API调用,并将数据返回给客户端(因为我在哪里可以看到它)。 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. 所有的cron作业都在使用特定的功能,但是我无法访问此功能GetTickerInfo,因为它已定义并且在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? 当我要在给定的时间手动刷新时,如何称呼它为cron作业,但又偶尔从客户端留下Meteor Call?
Can anyone show how would they implement this with for eg CRON package: percolatestudio/meteor-synced-cron
任何人都可以展示如何使用CRON软件包来实现这一点: 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.