From a4e3494065e7e6f19b953bad3b1e8b3955db27da Mon Sep 17 00:00:00 2001 From: Stephen Chen Date: Sat, 21 Oct 2017 13:55:56 +0800 Subject: [PATCH 1/2] fix `checkAndNotify` function flow bug --- bot.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bot.js b/bot.js index 4de8d3c..20a1078 100644 --- a/bot.js +++ b/bot.js @@ -43,18 +43,17 @@ function notify(projectPlatform, projectName, releasePage, results, cb) { function checkAndNotify(results, projectInfo, projectName, projectPlatform, cb) { if (needToNotify(results)) { - async.waterfall([ + async.series([ function (inner_cb) { const releasePage = site.siteUtil(projectPlatform).getReleasesPage(projectInfo) notify(projectPlatform, projectName, releasePage, results, inner_cb) } - ], function waterfallCallback(hasSomeError) { - if (hasSomeError) - return cb(new Error(`failed: ${projectName}`)) + ], function seriesCallback(err) { + if (err) + cb(new Error(`failed: ${projectName}`)) }) - } - - cb(null, `success: ${projectName}`) + } else + cb(null, `success: ${projectName}`) } /* From 5bb26e1bdb9f581ba7603bbab7f91bdb528390a1 Mon Sep 17 00:00:00 2001 From: Stephen Chen Date: Sat, 21 Oct 2017 14:41:15 +0800 Subject: [PATCH 2/2] add timeout --- lib/sites/project/github.js | 3 ++- lib/sites/project/pypi.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/sites/project/github.js b/lib/sites/project/github.js index 890f8a8..3f80a54 100644 --- a/lib/sites/project/github.js +++ b/lib/sites/project/github.js @@ -22,7 +22,8 @@ class Github { } getNewVersionInfo(check_date, project, cb) { - const req = request(`https://github.com/${project.project_author}/${project.project_name}/releases.atom`) + const url = `https://github.com/${project.project_author}/${project.project_name}/releases.atom` + const req = request(url, { timeout: 1500 }) const feedparser = new FeedParser({ addmeta: false }) const info = [] diff --git a/lib/sites/project/pypi.js b/lib/sites/project/pypi.js index 812b54d..d72917d 100644 --- a/lib/sites/project/pypi.js +++ b/lib/sites/project/pypi.js @@ -22,8 +22,9 @@ class Pypi { getNewVersionInfo(check_date, project, cb) { const info = [] + const url = `https://pypi.python.org/pypi/${project.project_name}/json` - request(`https://pypi.python.org/pypi/${project.project_name}/json`, (error, response, body) => { + request(url, { timeout: 3000 }, (error, response, body) => { if (error) return cb(error)