function currCycle(curCycle) {
return curCycle;
}
/**
* reduce the results from a previous mapping excercise
* @param {object} options describes what to do
* @param {object} mapResults this would contain results from a previous stage if present
* @return {array.*} test data to pass on to next stage
*/
function reduceTheResults(options, mapResults) {
Logger.log(mapResults);
// we'll have all the results here so consolidate
var results = mapResults.reduce ( function (p,c) {
(Array.isArray (c.results) ? c.results : [c.results]).forEach (function(d) {
p.push (d);
})
return p;
},[]);
return results;
}
function getAllEmails(options) {
var threads = GmailApp.search(options.query, options.start, options.max);
return [threads.length];
}
/**
* summarize the results of the orchestration
* @param {object} options describes what to do
* @param {object} reduceResults this would contain results from a previous stage if present
* @return {object} test data to pass on to next stage
*/
function logTheResults(options, reduceResults) {
// prepare handler
var handler = new cDbAbstraction.DbAbstraction ( eval(options.driver), options.parameters );
assert(handler.isHappy(), 'unable to get handler',options.driver);
// clear sheet if needed
if (options.clear) {
var result = handler.remove();
if (result.handleCode < 0) {
throw result.handleError;
}
}
// prepare data
var data = reduceResults[0].results;
var intSum = data.reduce(function(a, b) { return a + b; });
if(options.cycle === 0) {
options.sum = 0;
}
var cumSum = intSum + options.sum;
// set options
var opt = {
"sum": cumSum,
"starttime": options.starttime,
"max": MAX,
"query": QUERY,
"chunk": CHUNK
};
if(data.lastIndexOf(0) !== data.length - 1) {
opt.cycle = options.cycle + 1;
libSidebar('asyncService', ADDONNAME, gmailProfile(opt));
} else {
var totalTime = Math.round((new Date().getTime() - opt.starttime) / 1000);
result = handler.save({"total count": cumSum, "total time (s)": totalTime});
if (handler.handleCode < 0) {
throw JSON.stringify(result);
}
}
}
function assert (what,message,n) {
var fatal = true;
if (!Array.isArray(what)) what = [what];
var good = what.every(function(d) { return d });
var m = ('assertion' + n + (good ? ':success':':failure:'+JSON.stringify({message:message,tests:what})));
Logger.log(m);
if (!good && fatal) {
throw (n+'- '+m);
}
}