Skip to content

Commit

Permalink
answer callback when success with id
Browse files Browse the repository at this point in the history
set error_count to 0 when success
update README
  • Loading branch information
fengkx committed Dec 24, 2018
1 parent 3bff97b commit f645558
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ RSS 解析用的是 [rss-parser](https://www.npmjs.com/package/rss-parser),它
1. 推荐用 `pm2` 守护进程 `pm2 start index.js` 如果没有安装`pm2` 就先安装 `npm i -g pm2`

# TODO
1. export 命令
1. 代理
- [x] export 命令
- 代理
- unit test

# 配置项
**所有配置项都可以用环境变量或者直接在 `config/index.js`中修改**
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bot.action('UNSUB_ALL_YES',
RSS.unsubAll,
async (ctx, next) => {
const cb = ctx.callbackQuery;
const res = await ctx.telegram.answerCbQuery();
const res = await ctx.telegram.answerCbQuery(cb.id);
}
);

Expand Down
14 changes: 10 additions & 4 deletions utils/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ const Parser = require('rss-parser');
const config = require('../config');
const hashFeed = require('../utils/hashFeed');
const _pick = require('lodash.pick');
const {getAllFeeds, updateHashList, failAttempt, getFeedByUrl} = require('../proxies/rssFeed');
const schedule = require('node-schedule');
const logger = require('./logger');
const {
getAllFeeds,
updateHashList,
failAttempt,
getFeedByUrl,
resetErrorCount
} = require('../proxies/rssFeed');

const fetch = async (feedUrl) => {
try {
Expand All @@ -14,14 +20,14 @@ const fetch = async (feedUrl) => {
const parser = new Parser();
const feed = await parser.parseString(res.data);
const items = feed.items.slice(0, config.item_num);
const hashList = await Promise.all(
await resetErrorCount(feedUrl);
return await Promise.all(
items.map(async item => {
return _pick(item, ['link', 'title', 'content']);
})
);
return hashList;
} catch (e) {
failAttempt(feedUrl);
await failAttempt(feedUrl);
getFeedByUrl(feedUrl).then(feed => {
if (feed.error_count >= 5) {
logger.info(feed, 'ERROR_MANY_TIME')
Expand Down

0 comments on commit f645558

Please sign in to comment.