vsivsi / meteor-job-collection

A persistent and reactive job queue for Meteor, supporting distributed workers that can run anywhere.
https://atmospherejs.com/vsivsi/job-collection
Other
388 stars 68 forks source link

Two Jobs one after the other (with a gap of 5mins). #241

Open suryaiiit opened 7 years ago

suryaiiit commented 7 years ago

Hi,

I'm trying to create two jobs, one which loads the data (rss-feeds) and the second one filters the data. As rss-feeds takes some time I'm thinking of giving a gap/delay of 5mins, but I'm not able to achieve this with .delay();

One:

job = new Job(FeedsJobs, 'jobFeeds', { });

  job.retry({ retries: FeedsJobs.forever });

  job.repeat({
    repeats: FeedsJobs.forever,
    schedule: FeedsJobs.later.parse.text('every 30 mins')
  });

  job.save(function(error, result) {
    console.log('FeedsJobs Save - ', new Date(), error, result);
    job.ready();
  });

Two:

job = new Job(TalesJobs, 'jobTales', {});

        job.retry({ retries: TalesJobs.forever });

        job.delay(5*60*1000); //Note this.

        job.repeat({
          repeats: TalesJobs.forever,
          schedule: TalesJobs.later.parse.text('every 30 mins')
        });

        job.save(function(error, result) {
          console.log('TalesJobs Save - ', new Date(), error, result);
          job.ready();
        });

I even tried enclosing the entire Two code in setTimeout of 5mins, but even that dint work. Please suggest. Thanks.

vsivsi commented 7 years ago

You have a classic job dependency here. Sounds like you don't really want a delay of 5 (or whatever) minutes, you simply want job2 to wait until job1 is successfully finished. See:

https://github.com/vsivsi/meteor-job-collection#jobdependsdependencies---anywhere

suryaiiit commented 7 years ago

oh thats cool, will try that.

Sorry, my bad I should have thoroughly checked the documentation.