Skip to content

Commit

Permalink
added error handling to publish(). Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Sep 18, 2016
1 parent 8e611fe commit 2eb0ef2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-boss",
"version": "0.3.3",
"version": "0.3.4",
"description": "Queueing jobs in Node.js using PostgreSQL like a boss",
"main": "./lib/index.js",
"dependencies": {
Expand Down
8 changes: 7 additions & 1 deletion src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class Manager extends EventEmitter {

name = args[0];
data = args[1];

assert(typeof data != 'function', 'publish() cannot accept a function as the payload. Did you intend to use subscribe()?');

options = args[2];

} else if(typeof args[0] == 'object'){
Expand All @@ -168,8 +171,11 @@ class Manager extends EventEmitter {
options = job.options;
}

assert(name, 'boss requires all jobs to have a name');
options = options || {};

assert(name, 'boss requires all jobs to have a name');
assert(typeof options == 'object', 'options should be an object');

} catch (error){
return reject(error);
}
Expand Down
14 changes: 14 additions & 0 deletions test/publishTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ describe('publish', function(){
});
});

it('should fail with a function for data', function(finished) {
boss.publish('job', () => true).catch(error => {
assert(true);
finished();
});
});

it('should fail with a function for options', function(finished) {
boss.publish('job', 'data', () => true).catch(error => {
assert(true);
finished();
});
});

it('should accept single string argument', function(finished) {
var jobName = 'publishNameOnly';

Expand Down

0 comments on commit 2eb0ef2

Please sign in to comment.