Last active
September 13, 2017 20:05
-
-
Save paulosuzart/de6683fb03e2ae0a62b0d285f0edb622 to your computer and use it in GitHub Desktop.
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
{ | |
"vcs_url" : "https://github.com/circleci/mongofinil", | |
"build_url" : "https://circleci.com/gh/circleci/mongofinil/22", | |
"build_num" : 22, | |
"branch" : "master", | |
"vcs_revision" : "1d231626ba1d2838e599c5c598d28e2306ad4e48", | |
"committer_name" : "Allen Rohner", | |
"committer_email" : "[email protected]", | |
"subject" : "Don't explode when the system clock shifts backwards", | |
"body" : "", | |
"why" : "github", | |
"dont_build" : null, | |
"queued_at" : "2013-02-12T21:33:30Z", | |
"start_time" : "2013-02-12T21:33:38Z", | |
"stop_time" : "2013-02-12T21:34:01Z", | |
"build_time_millis" : 23505, | |
"username" : "circleci", | |
"reponame" : "mongofinil", | |
"lifecycle" : "finished", | |
"outcome" : "success", | |
"status" : "success", | |
"retry_of" : null, | |
"steps" : [ { | |
"name" : "configure the build", | |
"actions" : [ { | |
"bash_command" : null, | |
"run_time_millis" : 1646, | |
"start_time" : "2013-02-12T21:33:38Z", | |
"end_time" : "2013-02-12T21:33:39Z", | |
"name" : "configure the build", | |
"exit_code" : null, | |
"type" : "infrastructure", | |
"index" : 0, | |
"status" : "success" | |
} ] }, | |
{"name": "lein2 deps", | |
"actions": [ { | |
"bash_command" : "lein2 deps", | |
"run_time_millis" : 7555, | |
"start_time" : "2013-02-12T21:33:47Z", | |
"messages" : [ ], | |
"step" : 1, | |
"exit_code" : 0, | |
"end_time" : "2013-02-12T21:33:54Z", | |
"index" : 0, | |
"status" : "success", | |
"type" : "dependencies", | |
"source" : "inference", | |
"failed" : null | |
} ] }, | |
{"name" : "lein2 trampoline midje", | |
"actions" : [ { | |
"bash_command" : "lein2 trampoline midje", | |
"run_time_millis" : 2310, | |
"continue" : null, | |
"parallel" : true, | |
"start_time" : "2013-02-12T21:33:59Z", | |
"name" : "lein2 trampoline midje", | |
"messages" : [ ], | |
"step" : 6, | |
"exit_code" : 1, | |
"end_time" : "2013-02-12T21:34:01Z", | |
"index" : 0, | |
"status" : "failed", | |
"timedout" : null, | |
"infrastructure_fail" : null, | |
"type" : "test", | |
"source" : "inference", | |
"failed" : true | |
} ] | |
} ] | |
} |
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
var MongoClient = require('mongodb').MongoClient; | |
/** | |
* After the data is inserted it returs the count of succes / failure among all stored build data | |
*/ | |
function showStats(db, done) { | |
db.collection('builds').aggregate([{ | |
$group: { | |
_id: "$outcome", | |
count: {$sum: 1} | |
}, | |
}], function(err, result) { | |
if (err) { | |
done(err, 'Saved but unable to aggregate'); | |
} | |
done(null, result); | |
}); | |
} | |
module.exports = function (ctx, done) { | |
MongoClient.connect(ctx.data.MONGO_URL, function (err, db) { | |
if (err) { | |
done(err); | |
} | |
const buildsCollection = db.collection('builds'); | |
buildsCollection.insertOne(JSON.parse(ctx.body_raw), function (insertErr, result){ | |
if (insertErr) { | |
done(insertErr, 'Unable to insert build record'); | |
} | |
showStats(db, done); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use the tasks access this url: https://wt-3c4d6e49c62a7db180a095900783ffc5-0.run.webtask.io/hello