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.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
fix: Correctly compute `pendingRequestCount` in request queue (#1765)
Jiří Moravčík946535f23380
diff --git a/packages/memory-storage/src/resource-clients/request-queue.ts b/packages/memory-storage/src/resource-clients/request-queue.tsindex 0c32ea7b0..400039f4e 100644--- a/packages/memory-storage/src/resource-clients/request-queue.ts+++ b/packages/memory-storage/src/resource-clients/request-queue.ts@@ -185,7 +185,8 @@ export class RequestQueueClient extends BaseClient implements storage.RequestQue}existingQueueById.requests.set(requestModel.id, requestModel);- existingQueueById.pendingRequestCount += requestModel.orderNo === null ? 1 : 0;+ // We add 1 to pending requests if the request was not handled yet+ existingQueueById.pendingRequestCount += requestModel.orderNo !== null ? 1 : 0;existingQueueById.updateTimestamps(true);existingQueueById.updateItem(requestModel);@@ -230,7 +231,8 @@ export class RequestQueueClient extends BaseClient implements storage.RequestQue}existingQueueById.requests.set(requestModel.id, requestModel);- existingQueueById.pendingRequestCount += requestModel.orderNo === null ? 1 : 0;+ // We add 1 to pending requests if the request was not handled yet+ existingQueueById.pendingRequestCount += requestModel.orderNo !== null ? 1 : 0;result.processedRequests.push({requestId: requestModel.id,uniqueKey: requestModel.uniqueKey,@@ -288,14 +290,12 @@ export class RequestQueueClient extends BaseClient implements storage.RequestQue// the handled counts are updated correctly in all cases.existingQueueById.requests.set(requestModel.id, requestModel);- let handledCountAdjustment = 0;const isRequestHandledStateChanging = typeof existingRequest.orderNo !== typeof requestModel.orderNo;const requestWasHandledBeforeUpdate = existingRequest.orderNo === null;- if (isRequestHandledStateChanging) handledCountAdjustment += 1;- if (requestWasHandledBeforeUpdate) handledCountAdjustment = -handledCountAdjustment;-- existingQueueById.pendingRequestCount += handledCountAdjustment;+ if (isRequestHandledStateChanging) {+ existingQueueById.pendingRequestCount += requestWasHandledBeforeUpdate ? 1 : -1;+ }existingQueueById.updateTimestamps(true);existingQueueById.updateItem(requestModel);