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

Error: There is already a collection named "jobQueue" #252

Open holmrenser opened 7 years ago

holmrenser commented 7 years ago

As per the example I am running the following client-side code:

I have a button that submits a job

Template.feature.events({
  'click #submit': function(event,template){
    const jobQueue = JobCollection('jobQueue', { noCollectionSuffix: true });
    const job = new Job(jobQueue, 'test-job', { Id: this.ID })
    job.priority('normal').save()
  }
});

When doing this I run into the following error if I click the button more than once:

Error: There is already a collection named "jobQueue"
    at JobCollection.Mongo.Collection (collection.js:226)
    at JobCollectionBase [as constructor] (shared.coffee:132)
    at new JobCollection (client.coffee:37)
    at JobCollection (client.coffee:34)
    at Blaze.TemplateInstance.<anonymous> (feature.js:110)
    at blaze.js?hash=f33d3df…:3398
    at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3df…:3744)
    at fireCallbacks (blaze.js?hash=f33d3df…:3394)
    at Blaze.View.<anonymous> (blaze.js?hash=f33d3df…:3474)
    at fireCallbacks (blaze.js?hash=f33d3df…:2014)
vsivsi commented 7 years ago

Hi, don't instantiate a new collection with every click.

Move this code outside of your event handler:

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