fetchMarketData() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            var _iteratorNormalCompletion = true;
            var _didIteratorError = false;
            var _iteratorError = undefined;

            try {
                for (var _iterator = _this4.appIDs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                    let appID = _step.value;

                    _this4.logger.info(`Fetching prices for app ${appID}`);
                    let pageIndex = 1;
                    let total = 1;
                    let fetched = 0;
                    do {

                        // Make request to API
                        let response = yield _this4.queue.resolve(function () {
                            return (0, _nodeFetch2.default)(`${API_URL}&appid=${appID}` + `&start=${fetched}&count=${PAGE_SIZE}`);
                        });

                        if (response.status === 429) {
                            _this4.logger.warn('Made too many requests (429 status code)');
                            _this4.logger.warn(`Retrying in ${REQUEST_COOL_DOWN}ms`);
                            yield new Promise(function (resolve) {
                                return setTimeout(resolve, REQUEST_COOL_DOWN);
                            });
                            continue;
                        } else if (response.status !== 200) {
                            throw new Error(`Unable to fetch page #${pageIndex}: response code was ${response.status}`);
                        }

                        let page = yield response.json();
                        if (!page || Object.keys(page).length === 0) throw new Error('Response is empty');

                        if (!page.success) throw new Error(`Unable to fetch page #${pageIndex}`);

                        // Adjust total item counter
                        if (total !== page['total_count']) total = page['total_count'];

                        let results = page['results'];

                        // Save to DB
                        yield _this4.pushToDB(results);

                        fetched += results.length;
                        _this4.logger.info(`Fetched ${fetched} items of ${total}` + ` (${pageIndex} pages, ${Math.floor(fetched / total * 100)}%)`);
                        ++pageIndex;
                    } while (fetched < total);
                    _this4.logger.info(`Successfully fetched all prices for app ${appID}`);
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally {
                try {
                    if (!_iteratorNormalCompletion && _iterator.return) {
                        _iterator.return();
                    }
                } finally {
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
        })();
    }
/**
     * Retrieves market listings details from Steam.
     * @returns {Promise<void>}
     */
Retrieves market listings details from Steam.
@returns {Promise}
Retrieves market listings details from Steam . @returns { Promise }
fetchMarketData() {
        var _this4 = this;
        return _asyncToGenerator(function* () {
            var _iteratorNormalCompletion = true;
            var _didIteratorError = false;
            var _iteratorError = undefined;
            try {
                for (var _iterator = _this4.appIDs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                    let appID = _step.value;
                    _this4.logger.info(`Fetching prices for app ${appID}`);
                    let pageIndex = 1;
                    let total = 1;
                    let fetched = 0;
                    do {
                        let response = yield _this4.queue.resolve(function () {
                            return (0, _nodeFetch2.default)(`${API_URL}&appid=${appID}` + `&start=${fetched}&count=${PAGE_SIZE}`);
                        });
                        if (response.status === 429) {
                            _this4.logger.warn('Made too many requests (429 status code)');
                            _this4.logger.warn(`Retrying in ${REQUEST_COOL_DOWN}ms`);
                            yield new Promise(function (resolve) {
                                return setTimeout(resolve, REQUEST_COOL_DOWN);
                            });
                            continue;
                        } else if (response.status !== 200) {
                            throw new Error(`Unable to fetch page #${pageIndex}: response code was ${response.status}`);
                        }
                        let page = yield response.json();
                        if (!page || Object.keys(page).length === 0) throw new Error('Response is empty');
                        if (!page.success) throw new Error(`Unable to fetch page #${pageIndex}`);
                        if (total !== page['total_count']) total = page['total_count'];
                        let results = page['results'];
                        yield _this4.pushToDB(results);
                        fetched += results.length;
                        _this4.logger.info(`Fetched ${fetched} items of ${total}` + ` (${pageIndex} pages, ${Math.floor(fetched / total * 100)}%)`);
                        ++pageIndex;
                    } while (fetched < total);
                    _this4.logger.info(`Successfully fetched all prices for app ${appID}`);
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally {
                try {
                    if (!_iteratorNormalCompletion && _iterator.return) {
                        _iterator.return();
                    }
                } finally {
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
        })();
    }
fetchMarketData ( ) { var _this4 = this ; return _asyncToGenerator ( function * ( ) { var _iteratorNormalCompletion = true ; var _didIteratorError = false ; var _iteratorError = undefined ; try { for ( var _iterator = _this4 . appIDs [ Symbol . iterator ] ( ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) { let appID = _step . value ; _this4 . logger . info ( ` ${ appID } ` ) ; let pageIndex = 1 ; let total = 1 ; let fetched = 0 ; do { let response = yield _this4 . queue . resolve ( function ( ) { return ( 0 , _nodeFetch2 . default ) ( ` ${ API_URL } ${ appID } ` + ` ${ fetched } ${ PAGE_SIZE } ` ) ; } ) ; if ( response . status === 429 ) { _this4 . logger . warn ( 'Made too many requests (429 status code)' ) ; _this4 . logger . warn ( ` ${ REQUEST_COOL_DOWN } ` ) ; yield new Promise ( function ( resolve ) { return setTimeout ( resolve , REQUEST_COOL_DOWN ) ; } ) ; continue ; } else if ( response . status !== 200 ) { throw new Error ( ` ${ pageIndex } ${ response . status } ` ) ; } let page = yield response . json ( ) ; if ( ! page || Object . keys ( page ) . length === 0 ) throw new Error ( 'Response is empty' ) ; if ( ! page . success ) throw new Error ( ` ${ pageIndex } ` ) ; if ( total !== page [ 'total_count' ] ) total = page [ 'total_count' ] ; let results = page [ 'results' ] ; yield _this4 . pushToDB ( results ) ; fetched += results . length ; _this4 . logger . info ( ` ${ fetched } ${ total } ` + ` ${ pageIndex } ${ Math . floor ( fetched / total * 100 ) } ` ) ; ++ pageIndex ; } while ( fetched < total ) ; _this4 . logger . info ( ` ${ appID } ` ) ; } } catch ( err ) { _didIteratorError = true ; _iteratorError = err ; } finally { try { if ( ! _iteratorNormalCompletion && _iterator . return ) { _iterator . return ( ) ; } } finally { if ( _didIteratorError ) { throw _iteratorError ; } } } } ) ( ) ; }
Retrieves market listings details from Steam.
Retrieves market listings details from Steam .
// Make request to API // Adjust total item counter // Save to DB