not parsing args correctly when running jobs?
cmeiklejohn opened this issue · comments
When queuing a job up with a string with length greater than two, I'm getting failures when trying to run the job.
For instance:
resque.enqueue('things', 'build_thing', '1');
Jobs = {
...
build_thing: function(arg, callback) {
# arg gets set to 1
resque.worker('things', Jobs);
However, with an id greater than that I experience this:
resque.enqueue('things', 'build_thing', '22');
Jobs = {
...
build_thing: function(arg, callback) {
# arg gets set to 2
resque.worker('things', Jobs);
TypeError: string is not a function
at String.CALL_NON_FUNCTION (native)
Adjusted description to reflect that this is a problem with a string with length > 1.
Check this out and see if things work for you if you use an Array for the args. This maybe a good place to apply a splat in coffee-resque.
It is not working if I use an array. I get this with an array of numbers: TypeError: number is not a function
or with an array of Strings: TypeError: string is not a function
If you could share the code you are working on it would be helpful for me to diagnosis? Or at least the coffee-resque relevant codez? Something isn't setup quite right.
k, sure. one sec.
worker.js
var Jobs = {
succeed: function(arg, callback) { callback(); },
fail: function(arg, callback) { callback(new Error('fail')); },
build: function(build, callback) {
console.log('Build called with: ' + build);
callback(build);
}
};
var worker = resque.worker('builder', Jobs);
worker.on('job', function(worker, queue, job) {
console.log("Attempting job; worker: " + worker + " queue: " + queue + " job: " + job);
})
worker.start();
server.js
resque.enqueue('builder', 'build', JSON.stringify({
build_id: build.id
}));
Ok, so I'm assuming that you connected resque to redis. If you look at the enqueue method you shouldn't need to_json your args manually. Can you try just this in server.js. In the code above the args still aren't in an array.
resque.enqueue('builder', 'build', [{build_id: build.id}]);
That worked perfectly.
Splendid! Good luck and hit us with any feedback that you might have.
Sean
Thanks so much!