2016-11-18 88 views
1

我想知道是否有可能在任何特定的时间删除或修改MongoDB收集数据。流星Cron工作

把它看作微不足道的数据,必须在一天结束时删除/更新。 指向我的方向。

+1

https://atmospherejs.com/percolate/synced-cron –

+0

@Michel我要求你马上写一本关于流星的书。我们认真地期待它,你是知识的海洋。 –

+0

非常感谢@AnkurSoni! –

回答

0

随着流星我没有得到像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,你也可以当你需要更多的功能使用。