Content-Length: 263496 | pFad | http://github.com/apify/crawlee/pull/2792/commits/284274bffc1e4153e5afd1447751a4b253925f47

93 feat: stopping the crawlers gracefully with `BasicCrawler.stop()` by barjin · Pull Request #2792 · apify/crawlee · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stopping the crawlers gracefully with BasicCrawler.stop() #2792

Merged
merged 12 commits into from
Jan 20, 2025
Next Next commit
feat: stopping the crawlers gracefully with BasicCrawler.stop()
  • Loading branch information
barjin committed Jan 6, 2025
commit 284274bffc1e4153e5afd1447751a4b253925f47
12 changes: 12 additions & 0 deletions packages/basic-crawler/src/internals/basic-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,18 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
return stats;
}

/**
* Gracefully stops the current run of the crawler.
*
* This method will wait for all running tasks to finish. Only once all tasks are finished, the method will resolve.
*
* **WARNING:** If this method is called (and awaited) from a task (e.g. in the `requestHandler`), it will wait indefinitely, as the task will never finish.
*/
async stop() {
await this.autoscaledPool?.pause(); // Gracefully starve the this.autoscaledPool, so it doesn't start new tasks. Resolves once the pool is cleared.
await this.autoscaledPool?.abort(); // Resolves the `autoscaledPool.run()` promise in the `BasicCrawler.run()` method. Since the pool is already paused, it resolves immediately and doesn't kill any tasks.
}

async getRequestQueue() {
if (!this.requestQueue && this.requestList) {
this.log.warningOnce(
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/apify/crawlee/pull/2792/commits/284274bffc1e4153e5afd1447751a4b253925f47

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy