msavin / SteveJobs

A simple jobs queue that just works (for Meteor.js)
Other
207 stars 35 forks source link

cannot add Job #72

Closed tomasinouk closed 5 years ago

tomasinouk commented 5 years ago

hi, I am having an issue with probably Job.register, where

I am getting an error

TypeError: Cannot read property 'insert' of undefined
 at add (packages/msavin:sjobs/server/imports/actions/add/index.js:49:35)

When I do Jobs.run

I am trying the simple example from doco with in my server.js

Jobs.register({
  sayHi: function(name) {
    console.log('Hi ' + name)
    this.success()
  }
})

and then

Jobs.run('sayHi', 'Steve')

I can see a mongoDB collection job_data without any records though. Any idea, where the problem might be? Thank you

tomasinouk commented 5 years ago

OK, sort it out. Not my brightest moment.

leaving comment for further reference. both Jobs.register and Jobs.run need to run on the server. So when in documentation it said run it like Meteor Method, it is meant literally.

Need to create a Meteor Method, which will run the job.

eg. server.js

Jobs.register({
  sayHi: function(name) {
    console.log("Hi " + name)
    this.success()
})

Meteor.methods({
  runJob() {
    console.info('calling Job to run server ...')
    Jobs.run('sayHi', 'BAD BAD ROBOT')
  }
})

client

  methods: {
    callJob() {
      console.info("calling Job to run client ...");
      Meteor.call("runJob");
      // Jobs.run("sendReminder", "BAD BAD ROBOT");  // this does not belong here
    }
  }

hope nobody will need this