2

I want to run a 'scheduled job' in meteor which needs to be run only once at a specified time. I have the access of the date object. i've tried the below cron expression but didn't get the expected behavior.

shows next run @0

here's the code snippet.

schedule: function(parser) {
            var _year = bidStartTime.getFullYear();
            var _month = bidStartTime.getMonth();
            var _date = bidStartTime.getDate();
            var _hours = bidStartTime.getHours();
            var _min = bidStartTime.getMinutes();

            var bidAsCron = _min+' '+_hours+' '+_date+' '+ _month+' ? '+_year;
            console.log('parsed as ' + bidAsCron);

            // parser is a later.parse object

            //  sample parser.cron('25 17 5 10 ? 2015');
           // should 5th October 2015 at 5:25 pm

          return   parser.cron(bidAsCron);

        },
Munna
  • 109
  • 2
  • 12

1 Answers1

4

Using synced-cron version 1.3.0 you can specify parser.recur().on(date).fullDate(); to schedule a once off (i.e not recurring) event like this:

SyncedCron.add({
  name: cron_name,
  schedule: function (parser) {
    // ending_at is a Date object set to some future date
    // there is no recurrence
    return parser.recur().on(ending_at).fullDate();
  },
  job: function () {
    // job code
  }
});

working example: http://meteorpad.com/pad/mLfyoLnHSECPhQscz/synced-cron%20to%20run%20once

  • Didn't get the expected results. still getting the message `next run @0` – Munna Oct 05 '15 at 12:02
  • @Faysal are you sure you're using version 1.3.0? try `meteor add percolate:synced-cron@1.3.0` –  Oct 05 '15 at 12:41
  • Thanks. now working. I don't know where did i make the mistake before. after working on a separate project, all of a sudden , it starts working. Thanks again for helping me learn a new thing. – Munna Oct 05 '15 at 14:44