trying different approach
This commit is contained in:
@@ -6,9 +6,14 @@ const {
|
|||||||
SCRAPER_API_BASE_URL
|
SCRAPER_API_BASE_URL
|
||||||
} = require("../config/appConfig");
|
} = require("../config/appConfig");
|
||||||
|
|
||||||
const timeout = (ms) => {
|
const async timeout = (method, ms) => {
|
||||||
console.error("Waiting for ", ms);
|
console.error("Waiting for ", ms);
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => {
|
||||||
|
setTimeout(() => {
|
||||||
|
await method();
|
||||||
|
resolve();
|
||||||
|
}, ms);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetch = async (url, options = {}) => {
|
const fetch = async (url, options = {}) => {
|
||||||
@@ -27,8 +32,7 @@ const fetch = async (url, options = {}) => {
|
|||||||
? `${SCRAPER_API_BASE_URL}?api_key=${SCRAPER_API_KEY}&url=${urlToFetchThroughAPI}`
|
? `${SCRAPER_API_BASE_URL}?api_key=${SCRAPER_API_KEY}&url=${urlToFetchThroughAPI}`
|
||||||
: url;
|
: url;
|
||||||
const randomPauseMS = Math.floor(Math.random() * Math.floor(1500)) + 500;
|
const randomPauseMS = Math.floor(Math.random() * Math.floor(1500)) + 500;
|
||||||
await timeout(randomPauseMS);
|
return timeout(() => { nodeFetch(urlAdaptedForScraping, newOptions); }, randomPauseMS);
|
||||||
return nodeFetch(urlAdaptedForScraping, newOptions);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = fetch;
|
module.exports = fetch;
|
||||||
|
|||||||
Reference in New Issue
Block a user