2016-11-18 90 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,你也可以當你需要更多的功能使用。