This repository has been archived by the owner on Jul 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheroku.js
61 lines (51 loc) · 1.52 KB
/
heroku.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const Heroku = require('heroku-client');
const hl = require('highland');
// function getLogDrains(app) {
// const logDrainApi = heroku.apps(app.id).logDrains();
// const logDrainList = hl.wrapCallback(logDrainApi.list.bind(logDrainApi));
// //yield 'logDrains';
// return logDrainList
// }
function getLogDrains(app) {
const logDrainApi = heroku.apps(app.id).logDrains();
return hl(function (push, next) {
logDrainApi.list((err, res) => {
push(err, {app: app, logs: res});
push(null, hl.nil);
});
});
}
var heroku = new Heroku({
token: process.env.HEROKU_API_TOKEN
});
const hkApps = heroku.apps();
const appList = hl.wrapCallback(hkApps.list.bind(hkApps));
function showAppNameThat(filter) {
return appList()
.flatMap(x => x)
.map(getLogDrains)
.flatten()
.filter(filter)
.map(app => ({
name: app.app.name,
logs: app.logs
}))
.errors(e => console.log('error: ', e))
}
function haveNoLogsDrain(app) {
return app.logs.length === 0
}
function haveLogsDrain(app) {
return app.logs.length !== 0
}
module.exports = {
haveDrains: () => showAppNameThat(haveLogsDrain),
missingDrains: () => showAppNameThat(haveNoLogsDrain),
addDrain: addDrain,
}
function addDrain(appName, drainUrl) {
heroku.apps(appName).logDrains().create({url: drainUrl}, (err, res) => {
if (err) console.log('Error creating drain for %s. Error: ', appName, JSON.stringify(err));
else console.log('LogDrain created: %s, is now draining to %s', appName, drainUrl);
})
}