Skip to content

Commit 21ac509

Browse files
committed
feat(config): configuration of request cocurrency
make request while fetching configurable
1 parent 3c8810d commit 21ac509

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

config/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ module.exports = {
1818
UA:
1919
process.env.RSSBOT_UA ||
2020
'Mozilla/5.0 NodeRSSBot(https://github.com/fengkx/NodeRSSBot)',
21-
not_send: process.env.NOT_SEND || false
21+
not_send: process.env.NOT_SEND || false, // just for debug use
22+
concurrency: process.env.RSSBOT_CONCURRENCY || 200
2223
};

utils/fetch.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const got = require('./got');
22
const Parser = require('rss-parser');
33
const pMap = require('p-map');
4-
const config = require('../config');
54
const hashFeed = require('./hash-feed');
65
const _pick = require('lodash.pick');
76
const schedule = require('node-schedule');
@@ -13,15 +12,20 @@ const {
1312
getFeedByUrl,
1413
resetErrorCount
1514
} = require('../proxies/rssFeed');
16-
const { notify_error_count } = require('../config');
15+
const {
16+
notify_error_count,
17+
item_num,
18+
fetch_gap,
19+
concurrency
20+
} = require('../config');
1721

1822
const fetch = async (feedUrl) => {
1923
try {
2024
logger.debug(`fetching ${feedUrl}`);
2125
const res = await got.get(encodeURI(feedUrl));
2226
const parser = new Parser();
2327
const feed = await parser.parseString(res.body);
24-
const items = feed.items.slice(0, config.item_num);
28+
const items = feed.items.slice(0, item_num);
2529
await resetErrorCount(feedUrl);
2630
return items.map((item) => {
2731
return _pick(item, ['link', 'title', 'content', 'guid', 'id']);
@@ -98,7 +102,7 @@ const fetchAll = async () => {
98102
eachFeed
99103
});
100104
},
101-
{ concurrency: 100 }
105+
{ concurrency }
102106
);
103107

104108
logger.info('fetch a round');
@@ -115,10 +119,8 @@ function run() {
115119

116120
run();
117121
const rule = new schedule.RecurrenceRule();
118-
const unit = config.fetch_gap.substring(config.fetch_gap.length - 1);
119-
const gapNum = parseInt(
120-
config.fetch_gap.substring(0, config.fetch_gap.length - 1)
121-
);
122+
const unit = fetch_gap.substring(fetch_gap.length - 1);
123+
const gapNum = parseInt(fetch_gap.substring(0, fetch_gap.length - 1));
122124
const time_gaps = [];
123125
switch (unit) {
124126
case 'h':

0 commit comments

Comments
 (0)