Skip to content

Commit

Permalink
use pullBatch for everything
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Feb 17, 2015
1 parent 5d7171e commit 0f84cdd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
20 changes: 8 additions & 12 deletions lib/pubsub/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Subscription.prototype.delete = function(callback) {
* @param {boolean} options.returnImmediately - If set, the system will respond
* immediately. Otherwise, wait until new messages are available. Returns if
* timeout is reached.
* @param {number} options.maxCount - Limit the amount of messages pulled.
* @param {number} options.maxResults - Limit the amount of messages pulled.
* @param {function} callback - The callback function.
*
* @example
Expand All @@ -323,7 +323,7 @@ Subscription.prototype.delete = function(callback) {
* // Pull a single message.
* //-
* var opts = {
* maxCount: 1
* maxResults: 1
* };
*
* subscription.pull(opts, function(err, message) {
Expand All @@ -336,28 +336,24 @@ Subscription.prototype.delete = function(callback) {
*/
Subscription.prototype.pull = function(options, callback) {
var that = this;
var MAX_EVENTS_PULLED = 1000;
var apiEndpoint = 'subscriptions/pullBatch';

if (!callback) {
callback = options;
options = {};
}

if (!util.is(options.maxCount, 'number')) {
options.maxCount = 99999;
if (!util.is(options.maxResults, 'number')) {
options.maxResults = MAX_EVENTS_PULLED;
}

var single = options.maxCount === 1;
var apiEndpoint = single ? 'subscriptions/pull' : 'subscriptions/pullBatch';

var body = {
subscription: this.name,
returnImmediately: !!options.returnImmediately
returnImmediately: !!options.returnImmediately,
maxEvents: options.maxResults
};

if (!single) {
body.maxEvents = options.maxCount;
}

this.makeReq_('POST', apiEndpoint, null, body, function(err, response) {
if (err) {
callback(err);
Expand Down
9 changes: 5 additions & 4 deletions test/pubsub/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('Subscription', function() {
it('should default to batching', function(done) {
subscription.makeReq_ = function(method, path, query, body) {
assert.equal(path, 'subscriptions/pullBatch');
assert.equal(body.maxEvents, 99999);
assert.equal(body.maxEvents, 1000);
done();
};

Expand All @@ -219,13 +219,14 @@ describe('Subscription', function() {
it('should make correct api request', function(done) {
subscription.makeReq_ = function(method, path, qs, body) {
assert.equal(method, 'POST');
assert.equal(path, 'subscriptions/pull');
assert.equal(path, 'subscriptions/pullBatch');
assert.equal(body.subscription, SUB_FULL_NAME);
assert.strictEqual(body.returnImmediately, false);
assert.equal(body.maxEvents, 1);
done();
};

subscription.pull({ maxCount: 1 }, assert.ifError);
subscription.pull({ maxResults: 1 }, assert.ifError);
});

it('should execute callback with a message', function(done) {
Expand Down Expand Up @@ -267,7 +268,7 @@ describe('Subscription', function() {
done();
};

subscription.pull({ maxCount: 3 }, assert.ifError);
subscription.pull({ maxResults: 3 }, assert.ifError);
});

it('should execute callback with the messages', function(done) {
Expand Down

0 comments on commit 0f84cdd

Please sign in to comment.