Skip to content

Commit

Permalink
Fix #138
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitor Magán García committed May 24, 2013
1 parent d85b190 commit 82e0c9e
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 122 deletions.
8 changes: 4 additions & 4 deletions lib/agentLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function deleteTrans(req, res) {
var id = req.param('id_trans', null);

if (id) {
dataSrv.deleteTrans(id, function (e) {
dataSrv.deleteTrans(req.prefix, id, function (e) {
if (e) {
logger.info('deleteTrans', [
{errors: [e]},
Expand Down Expand Up @@ -334,7 +334,7 @@ function getQueue(req, res) {
res.send(500, {errors: [String(err)]});
} else {
var mapTrans = function (v) {
var id = v.split('|')[1];
var id = v.split('|')[2];
return {
id: id,
href: 'http://' + req.headers.host + '/trans/' + id + '?queues=All'
Expand Down Expand Up @@ -797,7 +797,7 @@ function transMeta(req, res) {
]);
res.send(400, {errors: ['missing id']});
} else {
dataSrv.getTransactionMeta(id, function (errM, dataM) {
dataSrv.getTransactionMeta(req.prefix, id, function (errM, dataM) {
if (errM) {
logger.info('transMeta', [
{errors: [errM]},
Expand All @@ -810,7 +810,7 @@ function transMeta(req, res) {
dataM = dataM || {};

if (queues !== null) {
dataSrv.getTransaction(id, queues, summary, function (errQ, dataQ) {
dataSrv.getTransaction(req.prefix, id, queues, summary, function (errQ, dataQ) {
if (errQ) {
logger.info('transMeta', [
{errors: [errQ]},
Expand Down
132 changes: 14 additions & 118 deletions lib/dataSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var pushTransaction = function(appPrefix, provision, callback) {
var priority = provision.priority + ':', //contains "H" || "L"
queues = provision.queue, //[{},{}] //list of ids
extTransactionId = uuid.v4(),
transactionId = config.dbKeyTransPrefix + extTransactionId,
transactionId = config.dbKeyTransPrefix + appPrefix + '|' + extTransactionId,
//setting up the bach proceses for async module.
processBatch = [],
dbTr = dbCluster.getTransactionDb(extTransactionId),
Expand Down Expand Up @@ -126,7 +126,7 @@ var pushTransaction = function(appPrefix, provision, callback) {

var updateTransMeta = function(appPrefix, extTransactionId, provision, callback) {
'use strict';
var transactionId = config.dbKeyTransPrefix + extTransactionId,
var transactionId = config.dbKeyTransPrefix + appPrefix + '|' + extTransactionId,
processBatch = [],
priority,
queue,
Expand Down Expand Up @@ -466,7 +466,7 @@ function retrieveData(queue, transactionList, callback) {
'use strict';
var ghostBusterBatch =
transactionList.map(function prepareDataBatch(transaction) {
var extTransactionId = transaction.split('|')[1],
var extTransactionId = transaction.split('|')[2],
dbTr = dbCluster.getTransactionDb(extTransactionId);
return checkData(queue, dbTr, transaction, extTransactionId);
});
Expand Down Expand Up @@ -506,7 +506,7 @@ function checkData(queue, dbTr, transactionId, extTransactionId) {
//uses state emum ('pending', 'closed', 'error')
//callback return transaction info

var getTransaction = function(extTransactionId, state, summary, callback) {
var getTransaction = function(appPrefix, extTransactionId, state, summary, callback) {
'use strict';
var err = null, //
dbTr = null, //
Expand All @@ -522,7 +522,7 @@ var getTransaction = function(extTransactionId, state, summary, callback) {
} else {
//obtain transaction info
dbTr = dbCluster.getTransactionDb(extTransactionId);
transactionId = config.dbKeyTransPrefix + extTransactionId;
transactionId = config.dbKeyTransPrefix + appPrefix + '|' + extTransactionId;
dbTr.hgetall(transactionId + ':state', function on_data(err, data) {
if (err) {
manageError(err, callback);
Expand Down Expand Up @@ -585,14 +585,14 @@ var getTransaction = function(extTransactionId, state, summary, callback) {


//callback return transaction info
var getTransactionMeta = function(extTransactionId, callback) {
var getTransactionMeta = function(appPrefix, extTransactionId, callback) {
'use strict';

var err, dbTr, transactionId;

//obtain transaction info
dbTr = dbCluster.getTransactionDb(extTransactionId);
transactionId = config.dbKeyTransPrefix + extTransactionId;
transactionId = config.dbKeyTransPrefix + appPrefix + '|' + extTransactionId;
dbTr.hgetall(transactionId + ':meta', function onDataMeta(err, data) {
if (err) {
manageError(err, callback);
Expand Down Expand Up @@ -651,11 +651,11 @@ var getQueue = function(appPrefix, queueId, callback) {
};


var deleteTrans = function(extTransactionId, cb) {
var deleteTrans = function(appPrefix, extTransactionId, cb) {
'use strict';
var dbTr = dbCluster.getTransactionDb(extTransactionId),
meta = config.dbKeyTransPrefix +
extTransactionId + ':meta', state = config.dbKeyTransPrefix +
meta = config.dbKeyTransPrefix + appPrefix + '|' +
extTransactionId + ':meta', state = config.dbKeyTransPrefix + appPrefix + '|'
extTransactionId + ':state';

dbTr.del(meta, state, function onDeleted(err) {
Expand All @@ -665,94 +665,13 @@ var deleteTrans = function(extTransactionId, cb) {
});
};

var setPayload = function(extTransactionId, payload, cb) {
'use strict';
var dbTr = dbCluster.getTransactionDb(extTransactionId),
meta = config.dbKeyTransPrefix +
extTransactionId + ':meta';

helper.exists(dbTr, meta, function(errE, value) {
if (errE) {
cb(errE);
}
else if (! value) {
cb(extTransactionId + ' does not exist');
}
else {

dbTr.hset(meta, 'payload', payload, function cbSetPayload(err) {
if (cb) {
cb(err);
}
});
}
});
};

var setUrlCallback = function(extTransactionId, urlCallback, cb) {
'use strict';
var dbTr = dbCluster.getTransactionDb(extTransactionId),
meta = config.dbKeyTransPrefix +
extTransactionId + ':meta';

helper.exists(dbTr, meta, function(errE, value) {
if (errE) {
cb(errE);
}
else if (! value) {
cb(extTransactionId + ' does not exist');
}
else {

dbTr.hset(meta, 'callback', urlCallback, function cbSetUrlCallback(err) {
if (cb) {
cb(err);
}
});
}
});
};


//deprecated
var setExpirationDate = function(extTransactionId, date, cb) {
'use strict';
var dbTr = dbCluster.getTransactionDb(extTransactionId),
meta = config.dbKeyTransPrefix +
extTransactionId + ':meta', state = config.dbKeyTransPrefix +
extTransactionId + ':state';

helper.exists(dbTr, meta, function(errE, value) {
if (errE) {
cb(errE);
}
else if (! value) {
cb(extTransactionId + ' does not exist');
}
else {
dbTr.hset(meta, 'expirationDate', date,
function cbHsetExpirationDate(errE) {
helper.setExpirationDate(dbTr, meta, {expirationDate: date},
function cbExpirationDateMeta(errM) {
helper.setExpirationDate(dbTr, state, {expirationDate: date},
function cbExpirationDateState(errS) {
if (cb) {
cb(errE || errM || errS);
}
});
});
});
}
});
};

var repushUndeliveredTransaction = function(appPrefix, queue, priority, extTransactionID, cb) {


var priority = priority + ':',
db = dbCluster.getDb(queue.id),
dbTr = dbCluster.getTransactionDb(extTransactionID),
transactionID = config.dbKeyTransPrefix + extTransactionID;
transactionID = config.dbKeyTransPrefix + appPrefix + '|' + extTransactionID;

async.parallel([
helper.pushHeadParallel(db, {id: appPrefix + queue.id}, priority, transactionID),
Expand Down Expand Up @@ -792,6 +711,7 @@ exports.pushTransaction = pushTransaction;

/**
*
* @param {string} appPrefix For secure/non secure behaviour.
* @param {string} extTransactionId valid uuid.v1.
* @param {string} state enum takes one of 'All', 'Pending', 'Delivered'.
* @param {boolean} summary true for summary, optional.
Expand All @@ -801,6 +721,7 @@ exports.getTransaction = getTransaction;

/**
*
* @param {string} appPrefix For secure/non secure behaviour.
* @param {string} extTransactionId valid uuid.v1.
* @param {string} state enum takes one of 'All', 'Pending', 'Delivered'.
* @param {boolean} summary true for summary, optional.
Expand Down Expand Up @@ -869,32 +790,7 @@ exports.getSecHash = getSecHash;
exports.deleteTrans = deleteTrans;

/**
*
* @param {string} extTransactionId valid uuid.v1.
* @param {string} payload
* @param cb
*/
exports.setPayload = setPayload;

/**
*
* @param {string} extTransactionId valid uuid.v1.
* @param {string} URL for callback.
* @param cb
*/

exports.setUrlCallback = setUrlCallback;

/**
*
* @param {string} extTransactionId valid uuid.v1.
* @param date
* @param cb
*/
exports.setExpirationDate = setExpirationDate;

/**
*
* @param {string} appPrefix For secure/non secure behaviour.
* @param transactionId
* @param provision
* @param callback
Expand Down
Loading

0 comments on commit 82e0c9e

Please sign in to comment.