Closed bluepuma77 closed 8 years ago
All linked to from the README for this project: https://github.com/vsivsi/meteor-job-collection-playground https://github.com/vsivsi/meteor-job-collection-playground-worker https://github.com/vsivsi/meteor-file-job-sample-app
It looks like, in the code you included above, you should be calling:
JobsQueue.processJobs('sendEmail', options, workerFunc);
See: https://github.com/vsivsi/meteor-job-collection#jq--jcprocessjobstype-options-worker---anywhere
The Job.processJobs()
form is for node.js code (outside of the Meteor environment). There's probably a way to make that work as well, but it's not the normal pattern when running within Meteor.
Thanks for the feedback, but it does not work for me within Meteor.
var queue = JobsQueue.processJobs(
'sendEmail', // Type of job to request
{
concurrency: 4,
payload: 1,
prefetch: 1
},
function (job, callback) {
// Only called when there is a valid job
console.log('[JobsQueue] Working job:', job.data);
job.done();
callback();
}
);
The code creates no output, so I assume the worker is not running.
I suggest you look at the sample apps I linked above.
I can't debug your app by just looking at code snippets. If you commit your entire sample app to a repo, I'll be happy to take a look.
The snippet is actually the full code to run the sample.
meteor create dummyapp
cd dummyapp
meteor add vsivsi:job-collection
cd server
vi main.js // replace with code from 1. post
meteor run
It will create a job in the queue, but the worker is not working. Note: the timeout in the code was added for the queue to be able to have time to initialize startJobServer(), not sure if this is required.
You did not save the job in the snippet provided, that is necessary.
Right! Thanks @Chugot!
// Create a job:
var job = new Job(JobsQueue, 'sendEmail', // type of job
// Job data that you define, including anything the job
// needs to complete. May contain links to files, etc...
{
address: 'bozo@clowns.com',
subject: 'Critical rainbow hair shortage',
message: 'LOL; JK, KThxBye.'
}
);
var result = job.save(); // <--- Need to save the job to the server/db!!!!
Wow, so plain and simple and still I didn't spot it. Thanks for your support!
Happens to all of us... Happy to help.
I am trying to get a worker to run within Meteor. I used most of the sample code provided, but somehow the worker is never triggered. Can you provide a working example of a worker within Meteor?
What's wrong with my code? The worker is never triggered.