Last active
December 15, 2015 01:49
-
-
Save stephentcannon/5183003 to your computer and use it in GitHub Desktop.
Meteor execution flow issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CLIENT SIDE | |
// kicks off process by inserting process/report request into | |
vat ts = new Date(); | |
var options = | |
{ start_date: '03/17/2013', | |
end_date: '03/18/2013', | |
client_updated_td: ts, | |
}; | |
Commissions.insert(doc); | |
// ALL SERVER SIDE | |
Commissions.allow({ | |
insert: function (userId, doc) { | |
// adds some params to doc | |
var ts = new Date(); | |
doc.created_td =ts; | |
doc.updated_td = ts; | |
doc.active = true; | |
doc.published = false; | |
doc.commissions_id = new Date().valueOf(); | |
doc.status = 'OPEN'; //OPEN, PROCESSED, VOIDED | |
Commissionitems.processItems(doc); | |
return true; | |
} | |
}); | |
Commissionitems.processItems = function(options){ | |
// code omitted for brevity options = doc | |
// but consists of a bunch of processing and aggregation. | |
// calls Commissionitems.insert(item) after each/aggregation item composition | |
// when done hands off to payment processing | |
Commissionpayments.processPayments(options); | |
}; | |
Commissionpayments.processPayments = function(options){ | |
// code omitted for brevity | |
// but consists of a bunch of processing and aggregation. | |
// calls Commissionpayments.insert(item) after each/aggregation of each Commissionitem down into a consolidated payment record | |
// when done notifies Commission | |
Commissions. | |
}; | |
Commissions.finalizeCommissions = function(options){ | |
// code not ommited for brevity | |
console.log('Commissions.finalizeCommissions options: '); | |
console.log(options); | |
console.log('options._id: ' + options._id); | |
try{ | |
Commissions.update(options._id,{$set: {status:'PROCESSED'}}, function(error){ | |
if(error){ | |
Logs.important(null, 'commissions', 'finalizeCommissions', error.toString(), 'finalizeCommissions resulted in error.'); | |
} else { | |
console.log('THIS SHOULD HAVE UPDATE COMMISSIONS TO PROCESSED BUT IT IS STILL OPEN UNLESS CALLED FROM OBSERVE'); | |
Commissionitems.update({commissions: options._id},{$set: {status:'PROCESSED'}},{multi: true}, function(error){ | |
if(error){ | |
Logs.important(null, 'commissions', 'finalizeCommissions', error.toString(), 'finalizeCommissions resulted in error.'); | |
} else { | |
Commissionpayments.update({commissions: options._id},{$set: {status:'PROCESSED'}},{multi: true}, function(error){ | |
if(error) | |
Logs.important(null, 'commissions', 'finalizeCommissions', error.toString(), 'finalizeCommissions resulted in error.'); | |
}); | |
} | |
}); | |
} | |
}); | |
}catch(error){ | |
Logs.important(null, 'commissions', 'finalizeCommissions', error.toString(), 'finalizeCommissions resulted in error.'); | |
} | |
}; | |
// ALTERNATIVELY IF I USE OBSERVE WHAT I WANT TO HAVE HAPPEN WORKS | |
var commissions_query = Commissions.find({active: true, status: 'OPEN'},{fields:{ | |
start_date:1, | |
end_date:1, | |
client_updated_td: 1, | |
created_td: 1, | |
updated_td: 1, | |
active: 1, | |
published: 1, | |
commissions_id: 1, | |
status: 1, | |
}}); | |
var commissions_handle = commissions_query.observe({ | |
added: function (doc) { | |
console.log('commissions_query.observe added doc'); | |
console.log(doc); | |
Commissionitems.processItems(doc); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment