Skip to content

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Aug 25, 2023
1 parent e04e3ae commit ac164d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 5 additions & 3 deletions packages/basic-crawler/src/internals/basic-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,15 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
return false;
}

source.inProgress.delete(request.id!);
// eslint-disable-next-line dot-notation
source['requestIdsInProgress'].delete(request.id!);
const delay = lastAccessTime + this.sameDomainDelayMillis - now;
this.log.debug(`Request ${request.url} (${request.id}) will be reclaimed after ${delay} milliseconds due to same domain delay`);
setTimeout(async () => {
this.log.debug(`Adding request ${request.url} (${request.id}) back to the queue`);
source?.inProgress.add(request.id!);
await source?.reclaimRequest(request);
// eslint-disable-next-line dot-notation
source['requestIdsInProgress'].add(request.id!);
await source.reclaimRequest(request);
}, delay);

return true;
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/storages/request_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class RequestList {
* Set of `uniqueKey`s of requests that were returned by fetchNextRequest().
* @internal
*/
inProgress = new Set<string>();
requestIdsInProgress = new Set<string>();

/**
* Set of `uniqueKey`s of requests for which reclaimRequest() was called.
Expand Down Expand Up @@ -492,7 +492,7 @@ export class RequestList {
});

this.nextIndex = state.nextIndex;
this.inProgress = new Set(state.inProgress);
this.requestIdsInProgress = new Set(state.inProgress);

// WORKAROUND:
// It happened to some users that state object contained something like:
Expand All @@ -512,12 +512,12 @@ export class RequestList {
deleteFromInProgress,
});
for (const uniqueKey of deleteFromInProgress) {
this.inProgress.delete(uniqueKey);
this.requestIdsInProgress.delete(uniqueKey);
}
}

// All in-progress requests need to be re-crawled
this.reclaimed = new Set(this.inProgress);
this.reclaimed = new Set(this.requestIdsInProgress);
}

/**
Expand Down Expand Up @@ -556,7 +556,7 @@ export class RequestList {
nextUniqueKey: this.nextIndex < this.requests.length
? this.requests[this.nextIndex].uniqueKey
: null,
inProgress: [...this.inProgress],
inProgress: [...this.requestIdsInProgress],
};
}

Expand All @@ -577,7 +577,7 @@ export class RequestList {
async isFinished(): Promise<boolean> {
this._ensureIsInitialized();

return this.inProgress.size === 0 && this.nextIndex >= this.requests.length;
return this.requestIdsInProgress.size === 0 && this.nextIndex >= this.requests.length;
}

/**
Expand All @@ -602,7 +602,7 @@ export class RequestList {
// Otherwise return next request.
if (this.nextIndex < this.requests.length) {
const request = this.requests[this.nextIndex];
this.inProgress.add(request.uniqueKey);
this.requestIdsInProgress.add(request.uniqueKey);
this.nextIndex++;
this.isStatePersisted = false;
return request;
Expand All @@ -621,7 +621,7 @@ export class RequestList {
this._ensureInProgressAndNotReclaimed(uniqueKey);
this._ensureIsInitialized();

this.inProgress.delete(uniqueKey);
this.requestIdsInProgress.delete(uniqueKey);
this.isStatePersisted = false;
}

Expand Down Expand Up @@ -742,7 +742,7 @@ export class RequestList {
* Checks that request is not reclaimed and throws an error if so.
*/
protected _ensureInProgressAndNotReclaimed(uniqueKey: string): void {
if (!this.inProgress.has(uniqueKey)) {
if (!this.requestIdsInProgress.has(uniqueKey)) {
throw new Error(`The request is not being processed (uniqueKey: ${uniqueKey})`);
}
if (this.reclaimed.has(uniqueKey)) {
Expand Down Expand Up @@ -774,7 +774,7 @@ export class RequestList {
handledCount(): number {
this._ensureIsInitialized();

return this.nextIndex - this.inProgress.size;
return this.nextIndex - this.requestIdsInProgress.size;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/storages/request_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export abstract class RequestProvider implements IStorage {

protected queueHeadIds = new ListDictionary<string>();
protected requestCache: LruCache<RequestLruItem>;
protected requestIdsInProgress = new Set<string>();
/** @internal */
requestIdsInProgress = new Set<string>();
protected recentlyHandledRequestsCache: LruCache<boolean>;

// TODO: RQv1 logic for stuck queues, this might not be needed anymore
Expand Down

0 comments on commit ac164d6

Please sign in to comment.