Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

RequestQueue.handledCount() function has been resurrected from deprecation

Jan Curnb92d5d02f59b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c89c7a821..57edcc808 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,14 +2,16 @@ xxx
====================
- Bugfix in BasicCrawler: async calls in `isFinishedFunction` were not awaited
- Better logging of memory overload errors
+- The `RequestQueue.handledCount()` function has been resurrected from deprecation,
+ in order to have compatible interface with `RequestList`.
0.14.15 / 2019-05-31
====================
- Fixes in `RequestQueue` to deal with inconsistencies in the underlying data storage
- **BREAKING CHANGE**: `RequestQueue.addRequest()` now sets the ID of the
newly added request to the passed `Request` object
-- **DEPRECATED**: The `RequestQueue.handledCount()` function has been deprecated,
- please use `RequestQueue.getInfo()` instead
+- The `RequestQueue.handledCount()` function has been deprecated,
+ please use `RequestQueue.getInfo()` instead.
0.14.14 / 2019-05-30
====================
diff --git a/src/request_queue.js b/src/request_queue.js
index afea3cb0a..aca12d93b 100644
--- a/src/request_queue.js
+++ b/src/request_queue.js
@@ -652,14 +652,19 @@ export class RequestQueue {
/**
* Returns the number of handled requests.
*
+ * This function is just a convenient shortcut for:
+ *
+ * ```javascript
+ * const { handledRequestCount } = await queue.getInfo();
+ * ```
+ *
* @return {Promise<number>}
* @deprecated
*/
async handledCount() {
- log.deprecated('RequestQueue.handledCount() is deprecated, please use RequestQueue.getInfo() instead.');
-
- const queueInfo = await requestQueues.getQueue({ queueId: this.queueId });
- return queueInfo.handledRequestCount;
+ // NOTE: We keep this function for compatibility with RequestList.handledCount()
+ const { handledRequestCount } = await this.getInfo();
+ return handledRequestCount;
}
/**
@@ -680,9 +685,9 @@ export class RequestQueue {
* createdAt: new Date("2015-12-12T07:34:14.202Z"),
* modifiedAt: new Date("2015-12-13T08:36:13.202Z"),
* accessedAt: new Date("2015-12-14T08:36:13.202Z"),
- * totalRequestCount: 0,
- * handledRequestCount: 0,
- * pendingRequestCount: 0,
+ * totalRequestCount: 25,
+ * handledRequestCount: 5,
+ * pendingRequestCount: 20,
* }
* ```
*
@@ -995,9 +1000,8 @@ export class RequestQueueLocal {
}
async handledCount() {
- await this.initializationPromise;
- this._updateMetadata();
- return this._handledCount;
+ const { handledRequestCount } = await this.getInfo();
+ return handledRequestCount;
}
async getInfo() {