Created
January 4, 2014 21:11
-
-
Save spollack/8260776 to your computer and use it in GitHub Desktop.
Node + Streamline Blog Examples
This file contains hidden or 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
function login_callbacks(email, password, onCompletion) { | |
db.crudOp('account', 'read', {conditions:{email:email}}, function (error, dbAccount) { | |
if (error) { | |
return onCompletion(error, null); | |
} | |
bcrypt.compare(password, dbAccount.password_hash, function (error, match) { | |
if (error) { | |
return onCompletion(error, null); | |
} | |
if (!match) { | |
return onCompletion(new Error('incorrect credentials'), null); | |
} | |
db.crudOp('account', 'update', {conditions:{email:email}, values:{last_login_at:new Date()}}, onCompletion); | |
}); | |
}); | |
} |
This file contains hidden or 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
function login_streamline(email, password, _) { | |
var dbAccount = db.crudOp('account', 'read', {conditions: {email: email}}, _); | |
if (!bcrypt.compare(password, dbAccount.password_hash, _)) { | |
throw new Error('incorrect credentials'); | |
} | |
return db.crudOp('account', 'update', {conditions: {id: dbAccount.id}, values: {last_login_at: new Date()}}, _); | |
} |
This file contains hidden or 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
function analyze_async(idLow, idHigh, onCompletion) { | |
async.waterfall([ | |
function (callback) { | |
db.crudOp('company', 'find', {conditions:{and:[{id:{gte:idLow}}, {id:{lte:idHigh}}]}, order:'id ASC'}, function (error, dbCompanies) { | |
callback(error, dbCompanies); | |
}); | |
}, | |
function (dbCompanies, callback) { | |
if (dbCompanies) { | |
analyze_async_helper(dbCompanies, callback); | |
} else { | |
async.nextTick(callback); | |
} | |
} | |
], onCompletion); | |
} | |
function analyze_async_helper(dbCompanies, onCompletion) { | |
async.eachLimit( | |
dbCompanies, | |
NUM_IN_PARALLEL, | |
function (dbCompany, callback) { | |
try { | |
var extractedData = JSON.parse(dbCompany.extracted_data); | |
} catch (error) { | |
log(error); // log and press on | |
return async.nextTick(callback); | |
} | |
analyzeData(dbCompany.id, extractedData, function (error) { | |
if (error) { | |
log(error); // log and press on | |
} | |
return callback(null); | |
}); | |
}, | |
onCompletion | |
); | |
} |
This file contains hidden or 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
function analyze_streamline(idLow, idHigh, _) { | |
var dbCompanies = db.crudOp('company', 'find', {conditions:{and:[{id:{gte:idLow}}, {id:{lte:idHigh}}]}, order:'id ASC'}, _); | |
if (dbCompanies) { | |
dbCompanies.forEach_(_, NUM_IN_PARALLEL, function(_, dbCompany) { | |
try { | |
var extractedData = JSON.parse(dbCompany.extracted_data); | |
analyzeData(dbCompany.id, extractedData, _); | |
} catch (error) { | |
log(error); // log and press on | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment