Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. promisifiedAggregation(global.chooseDb(`metric`).collection(`releasesProd`), [
  2.   {
  3.     $project: {
  4.       date: 1,
  5.       _id: 0,
  6.       number: 1,
  7.       startDate: {$subtract: [`$date`, 1000 * 60 * 60 * 24 * 14]},
  8.     },
  9.   },
  10.   {$sort: {number: 1}},
  11. ])
  12.   .map(release =>
  13.     Promise.all(
  14.       promisifiedAggregation(
  15.         global.chooseDb(`jmeter`).collection(`build_params`),
  16.         [
  17.           {
  18.             $match: {
  19.               executionDateUTC: {$gt: release.startDate, $lte: release.date},
  20.             },
  21.           },
  22.           {$project: {id: 1, source: 1}},
  23.           {$group: {id: `$source`, builds: {$push: `$_id`}}},
  24.         ]
  25.       ).map(build =>
  26.         promisifiedAggregation(
  27.           global.chooseDb(`jmeter`).collection(build.source),
  28.           [
  29.             {$match: {title: {$in: build.builds}}},
  30.             {$project: {'all.count': 1, 'ko.count': 1, 'ok.count': 1}},
  31.             {
  32.               $group: {
  33.                 _id: build.source,
  34.                 success: {$sum: `$ok.count`},
  35.                 failure: {$sum: `$ko.count`},
  36.                 all: {$sum: `$all.count`},
  37.               },
  38.             },
  39.           ]
  40.         )
  41.       )
  42.     ).then(builds => ({releaseId: release.id, builds}))
  43.   )
  44.   .reduce((aggregation, {releaseId, builds}) =>
  45.     Object.assign(aggregation, {[releaseId]: builds})
  46.   );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement