Skip to content

Commit

Permalink
Merge pull request #628 from joola/feature/#627
Browse files Browse the repository at this point in the history
#627 added support for beacon insert wait
  • Loading branch information
itayw committed Nov 11, 2014
2 parents f535a31 + cb00081 commit 55eba1c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.1.5
version: 0.1.8
interfaces:
webserver:
enabled: true
Expand Down Expand Up @@ -67,6 +67,8 @@ store:
mongodb:
dsn: mongodb://localhost:27017/cache
expireafterseconds: 0
beacon:
wait: true
dispatch:
enabled: true
expires: 60
Expand Down
22 changes: 18 additions & 4 deletions lib/dispatch/beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ exports.insert = {
description: "",
inputs: {
required: ['workspace', 'collection', 'document'],
optional: [ 'options']
optional: ['options']
},
_outputExample: {},
_permission: ['beacon:insert'],
Expand All @@ -156,6 +156,16 @@ exports.insert = {
_params.workspace = req.user.workspace;
_params.collection = req.parsed.collection;
_params.document = req.parsed.document || req.parsed.payload;


var w = joola.config.get('beacon').hasOwnProperty('wait') ? joola.config.get('beacon:wait') : false;
if (!req.parsed.options)
req.parsed.options = {
wait: w
};
else if (!req.parsed.options.hasOwnProperty('wait'))
req.parsed.options.wait = w;

if (typeof _params.document === 'string') {
try {
_params.document = JSON.parse(_params.document);
Expand Down Expand Up @@ -183,10 +193,14 @@ exports.insert = {
return router.responseSuccess(result, headers, req, res);
};
if (joola.dispatch.enabled)
joola.dispatch.request(_token._ || _token, 'beacon:insert', _params, cb);
joola.dispatch.request(_token._ || _token, 'beacon:insert', _params, req.parsed.options.wait ? cb : function () {
});
else
exports.insert.run.apply(this, [context, _params.workspace, _params.collection, _params.document, _params.options, cb]);

exports.insert.run.apply(this, [context, _params.workspace, _params.collection, _params.document, _params.options, req.parsed.options.wait ? cb : function () {
}]);
if (!req.parsed.options.wait) {
cb(null, _params.document, {});
}
}
catch (ex) {
return router.responseError(500, new router.ErrorTemplate(ex), req, res);
Expand Down

0 comments on commit 55eba1c

Please sign in to comment.