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

How to properly connect JobCollection between 2 Meteor servers? #249

Closed joncursi closed 7 years ago

joncursi commented 7 years ago

I am having the same issue mentioned here but I can't seem to figure out what I am missing.

I have to Meteor servers, one is my application server and the other is a jobs server that needs to do the work.

On the application server (running locally on port 3000):

const jc = JobCollection('jobs', {
  noCollectionSuffix: true,
});
jc.startJobServer();

Meteor.setInterval(() => {
  const job = new Job(jc, 'testTitle', {
    date: new Date(),
  });

  job.priority('normal')
    .retry({
      retries: 5,
      wait: 1000 * 10,
    })
    .save();
}, 1000 * 60);

I can see new jobs being stuffed into the jobs collection in MongoDB. Great!

Now, on the jobs server (running locally on port 6000):

import { DDP } from 'meteor/ddp-client'

Meteor.startup(() => {
  const connection = DDP.connect('localhost:3000');
  const jc = JobCollection('jobs', {
    connection,
  });

  console.log('here');

  const test = jc.getJob('xJsCEBXFBMEeMP9Nj'); // Meteor hangs here!
  console.log(test);
});

I see that "here!" gets logged out to console, but Meteor never prints the job I asked for because it gets hung up on jc.getJob(...).

screen shot 2017-07-11 at 1 05 34 am

What am I doing wrong here? 😿

joncursi commented 7 years ago

I'm not sure if it makes a difference, but I am using a dedicated MongoDB replica set, not the Mongo instance built into Meteor.

joncursi commented 7 years ago

Derp! That was it! Since I'm not using the built-in Mongo on the application server, I don't need to DDP connect to it. I can just instantiate a new JobCollection:

  const jc = JobCollection('jobs', {
    noCollectionSuffix: true,
  });

  console.log('here');

  const test = jc.getJob('xJsCEBXFBMEeMP9Nj');
  console.log(test);