-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
46 lines (42 loc) · 1.12 KB
/
handler.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
'use strict';
const fetch = require('./services/fetch');
const notify = require('./services/notify');
const persist = require('./services/persist');
const Q = require('q');
let config;
try {
config = require('./config');
} catch (e) {
config = {
notifyUrl: 'http://www.example.com'
};
}
const comicConfig = [
{
name: 'dilbert',
fetcher: fetch.getDilbertComicUrl
}, {
name: 'garfield',
fetcher: fetch.getGarfieldComicUrl
}, {
name: 'commitstrip',
fetcher: fetch.getCommitStripUrl
}, {
name: 'xkcd',
fetcher: fetch.getXKCDUrl
}, {
name: 'daily',
fetcher: fetch.getDailyUrl
}, {
name: 'turnoff',
fetcher: fetch.getTurnoffUrl
}];
module.exports.checkComics = (event, context, callback) => {
Q.all(Array.from(comicConfig, commic => {
commic.fetcher()
.then(imgUrl => persist.putIfNotExists(commic.name, imgUrl))
.then(url => notify.notifySlack(config.notifyUrl, url));
}))
.then(() => callback(null, 'OK'))
.catch(err => callback(err, null));
};