流星Cron工作
答
有两个不错的选择做cron作业流星:
- https://github.com/percolatestudio/meteor-synced-cron
- https://github.com/vsivsi/meteor-job-collection
从我的经验,如果你的使用情况很简单,你需要一个快速,轻量级解决方案meteor-synced-cron应该没问题。如果你的任务更复杂,你需要更多的控制作业,然后去jobs-collection
+0
感谢帮助meteor-synced-cron为我做的。 –
答
随着流星我没有得到像cron
标准节点包,如流星投诉正常工作,并显示消息使用纤维。对于一个简单的日常任务,我已经创建了一个直接使用Meteor.setTimeout()的函数。这样它将保持Meteor环境可用,所以你可以每天进行数据库清理。
它稍后使用节点包仅用于启动'cron'作业的计划。您可以使用要调用的函数名称替换yourDailyCleanup。
import { Meteor } from 'meteor/meteor';
import later from 'later';
function scheduleTimeout(sched, fn) {
const nowMilli = Date.now();
const next = later.schedule(sched).next(1,nowMilli+1001);
console.log('next schedule',next);
const diffMile = next.getTime() - nowMilli;
Meteor.setTimeout(function() {
scheduleTimeout(sched,fn);
fn();
} , diffMile);
}
Meteor.startup(function() {
console.log('Startup');
later.date.localTime();
// scheduleTimeout(later.parse.recur().every(2).minute(), function() { console.log('test job');});
scheduleTimeout(later.parse.recur().on('23:00:00').time(), yourDailyCleanup);
});
的代码是基于包percolatestudio:meteor-synced-cron,你也可以当你需要更多的功能使用。
https://atmospherejs.com/percolate/synced-cron –
@Michel我要求你马上写一本关于流星的书。我们认真地期待它,你是知识的海洋。 –
非常感谢@AnkurSoni! –