diff --git a/lib/gearmanode/client.js b/lib/gearmanode/client.js index bfe5427..ef9ac5c 100644 --- a/lib/gearmanode/client.js +++ b/lib/gearmanode/client.js @@ -152,7 +152,7 @@ Client.prototype.submitJob = function(name, payload, options) { } else { jobServer.jobsWaiting4Created.push(job); // add to queue of submited jobs waiting for confirmation job.jobServerUid = jobServer.getUid(); // store job server UID on job to later usage - job.emit('submited'); + process.nextTick(function() { job.emit('submited'); }); Client.logger.log('debug', 'job submited, name=%s, unique=%s', job.name, job.unique); } } diff --git a/lib/gearmanode/version.js b/lib/gearmanode/version.js index 5b4b99f..4500f0d 100644 --- a/lib/gearmanode/version.js +++ b/lib/gearmanode/version.js @@ -19,6 +19,7 @@ exports.VERSION_HISTORY = [ + ['0.1.8', '2014-24-08', 'Enh #16, BF #17'], ['0.1.7', '2014-14-07', 'BF #14'], ['0.1.6', '2014-17-06', 'BF #13'], ['0.1.5', '2014-20-03', 'added SET_CLIENT_ID; integration with Travis CI; BF #9'], diff --git a/package.json b/package.json index 8b669b2..60faadf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gearmanode", - "version": "0.1.7", + "version": "0.1.8", "description": "Node.js library for the Gearman distributed job system with support for multiple servers", "keywords": ["gearman", "distributed", "message queue", "job", "worker"], "author": "Vaclav Sykora ", diff --git a/test/test-client.js b/test/test-client.js index 730f823..f8e1900 100644 --- a/test/test-client.js +++ b/test/test-client.js @@ -83,7 +83,6 @@ describe('Client', function() { c.submitJob('reverse').should.be.an.instanceof(Error); }) it('should emit `submited` if job sent to server', function(done) { - js = c.jobServers[0]; var job = c.submitJob('reverse', 'hi'); js.jobsWaiting4Created.length.should.equal(0); job.once('submited', function() { @@ -102,6 +101,17 @@ describe('Client', function() { done(); }) }) + it('should emit `submited` when job server already connected (BF #17)', function(done) { + js.connect(function() { + var job = c.submitJob('reverse', 'hi'); + job.once('submited', function() { + job.jobServerUid.should.equal(js.getUid()); + job.processing.should.be.true; + done(); + }); + }); + + }) })