Post number of errors in run to Slack.
This commit is contained in:
parent
9899709782
commit
e1af0db0bb
|
|
@ -37,7 +37,7 @@ class App {
|
|||
|
||||
return runOptionalFunction(plugins, 'open', {storageManager}, this.options)
|
||||
.then(() => queueHandler.run(urlSources))
|
||||
.tap(() => runOptionalFunction(plugins, 'close', this.options));
|
||||
.tap((errors) => runOptionalFunction(plugins, 'close', this.options, errors));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
let throwIfMissing = require('../../support/util').throwIfMissing,
|
||||
Promise = require('bluebird'),
|
||||
path = require('path'),
|
||||
util = require('util'),
|
||||
merge = require('lodash.merge'),
|
||||
Slack = require('node-slack');
|
||||
|
||||
|
|
@ -13,21 +14,27 @@ const defaultOptions = {
|
|||
};
|
||||
|
||||
module.exports = {
|
||||
name() { return path.basename(__dirname); },
|
||||
name() {
|
||||
return path.basename(__dirname);
|
||||
},
|
||||
open(context, options) {
|
||||
throwIfMissing(options.slack, ['hookUrl', 'userName'], 'slack');
|
||||
|
||||
this.options = merge({}, defaultOptions, options.slack);
|
||||
this.slack = new Slack(this.options.hookUrl);
|
||||
|
||||
if (!this.options.channel.startsWith('#'))
|
||||
this.options.channel = '#' + this.options.channel;
|
||||
},
|
||||
close() {
|
||||
return this.slack.sendAsync({
|
||||
text: 'Sitespeed done!',
|
||||
channel: this.options.channel,
|
||||
username: this.options.userName
|
||||
close(errors, options) {
|
||||
options = merge({}, defaultOptions, options.slack);
|
||||
const slack = new Slack(options.hookUrl);
|
||||
|
||||
if (!options.channel.startsWith('#'))
|
||||
options.channel = '#' + options.channel;
|
||||
|
||||
let text = 'Sitespeed done!';
|
||||
if (errors.length > 0)
|
||||
text += util.format(' (%d) errors', errors.length);
|
||||
|
||||
return slack.sendAsync({
|
||||
text: text,
|
||||
channel: options.channel,
|
||||
username: options.userName
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue