Created
January 5, 2017 06:44
-
-
Save Pradnya-Paranjape/54d6879c04c83bd5185dc9d784ac22af to your computer and use it in GitHub Desktop.
move bblite
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
applicationModel.prototype.moveBbliteToAws = function(entity_type, paramLimit, paramChunk, company_id, cronFlag, start_date, end_date, timeFrame) { | |
var self = this; | |
return new Promise(function(fulfill, reject) { | |
var limit = paramLimit || 10, | |
chunk = paramChunk || 5, | |
whereCond = "", | |
selectParams = ""; | |
if (entity_type === 'applications') { | |
selectParams = ' uuid, bblite, outE("belongs_to")[type="Application_Company"].in.uuid as company_id'; | |
} else { | |
selectParams = ' uuid, bblite, company_id'; | |
if (company_id) { | |
whereCond = ' company_id = "' + company_id + '" and '; | |
} | |
} | |
if (timeFrame) { | |
const currentDateFormatted = self.get_date_in_uk_format(); | |
end_date = self.dateformat(currentDateFormatted, 'yyyy-mm-dd HH:mm:ss'); | |
var yesterdaysDate = self.dateformat((new Date(new Date() - 24 * 60 * 60 * 1000)), "yyyy-mm-dd HH:mm:ss"); | |
var oneweek = self.dateformat((new Date(new Date() - 168 * 60 * 60 * 1000)), "yyyy-mm-dd HH:mm:ss"); | |
var twoweek = self.dateformat((new Date(new Date() - 336 * 60 * 60 * 1000)), "yyyy-mm-dd HH:mm:ss"); | |
var thirtyday = self.dateformat((new Date(new Date() - 720 * 60 * 60 * 1000)), "yyyy-mm-dd HH:mm:ss"); | |
start_date = yesterdaysDate; | |
switch (timeFrame) { | |
case '1week': | |
{ | |
start_date = oneweek; | |
break; | |
}; | |
case '1day': | |
{ | |
start_date = yesterdaysDate; | |
break; | |
}; | |
case '2week': | |
{ | |
start_date = twoweek; | |
break; | |
}; | |
case '30day': | |
{ | |
start_date = thirtyday; | |
break; | |
} | |
} | |
whereCond = self.util.format(" modified_bblite between '%s' and '%s'", start_date, end_date); | |
} else { | |
whereCond = self.util.format(" modified_bblite between '%s' and '%s'", start_date, end_date); | |
if (cronFlag === true) { | |
whereCond = self.util.format(" bblite is not null and created_date_time between '%s' and '%s'", start_date, end_date); | |
} | |
} | |
var qry = self.util.format("select %s from %s where %s limit %s", selectParams, entity_type, whereCond, limit); | |
if (company_id && entity_type === 'applications') { | |
qry = self.util.format('select %s from (select expand(in("belongs_to")) from companies where uuid = "%s") where %s limit %s', selectParams, company_id, whereCond, limit); | |
} | |
console.log(qry); | |
self.db.query(qry) | |
.then(function(entities) { | |
if (!self.lo.isEmpty(entities)) { | |
var sizedArray = self.lo.chunk(entities, chunk); | |
var companyModel = self.app.get('company_model'); | |
self.lo.filter(sizedArray, function(size) { | |
companyModel.writeToMessageQueue(self.config.queue.topic_move_bblite, { | |
entity_data: size, | |
entity_type: entity_type, | |
company_id: company_id | |
}); | |
}); | |
fulfill(true); | |
} else { | |
fulfill([]); | |
} | |
}) | |
.catch(function(e) { | |
reject(e); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment