-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
77 lines (67 loc) · 2.52 KB
/
server.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict";
const { cloneDeep } = require("lodash");
const config = require("config").myApi;
const redis = require("redis");
const Raven = require("raven");
const LastfmWorker = require("./lib/workers/lastfmWorker");
const LastfmService = require("./lib/services/lastfmService");
const LastfmClient = require("./lib/clients/lastfmClient").User;
const PinboardWorker = require("./lib/workers/pinboardWorker");
const PinboardService = require("./lib/services/pinboardService");
const PinboardClient = require("./lib/clients/pinboardClient");
const PocketWorker = require("./lib/workers/pocketWorker");
const PocketService = require("./lib/services/pocketService");
const PocketClient = require("./lib/clients/pocketClient");
const { getLoggingWorkerCallback, parseRedisUrl } = require("./lib/tools");
const vars = require("./lib/vars");
let redisConfig = cloneDeep(config.redis);
Raven.config(config.sentry.dsn, {
environment: config.environment,
debug: config.environment === "development",
release: config.commit,
}).install();
if (redisConfig.url) {
redisConfig = Object.assign(redisConfig, parseRedisUrl(config.redis.url));
}
const clients = {
redis: redis.createClient(redisConfig.port, redisConfig.host),
lastfm: new LastfmClient(config.lastfm.apiKey, config.lastfm.user),
pinboard: new PinboardClient(config.pinboard.apiToken),
pocket: new PocketClient(config.pocket.consumerKey),
};
if (redisConfig.password) {
clients.redis.auth(redisConfig.password);
}
const workers = {
lastfm: new LastfmWorker({
redisClient: clients.redis,
lastfmClient: clients.lastfm,
callback: getLoggingWorkerCallback(LastfmWorker.name),
}),
pinboard: new PinboardWorker({
redisClient: clients.redis,
pinboardClient: clients.pinboard,
callback: getLoggingWorkerCallback(PinboardWorker.name),
}),
pocket: new PocketWorker({
redisClient: clients.redis,
pocketClient: clients.pocket,
callback: getLoggingWorkerCallback(PocketWorker.name),
}),
};
const services = {
lastfm: new LastfmService({ redisClient: clients.redis }),
pinboard: new PinboardService({ redisClient: clients.redis }),
pocket: new PocketService({
pocketClient: clients.pocket,
redisClient: clients.redis,
pocketWorker: workers.pocket,
}),
};
workers.lastfm.start(vars.lastfm.rateLimitsMS.defaultLimit * 5);
workers.pinboard.start(vars.pinboard.rateLimitsMS.defaultLimit * 3);
services.pocket.startWorker();
const app = require("./lib/app")(services);
app.listen(config.port, () => {
console.log(`listening on port ${config.port}`);
});