Apify & CrawleeA&CApify & Crawlee
Powered by
incredible-moccasinI
Apify & Crawlee•2y ago•
4 replies
incredible-moccasin

Unexpected results when currying a value into the request handler

I need to curry a value into my request handler. When I do this, my first invocation of the crawler runs as expected, but the second invocation reaches maxRequestsPerCrawl immediately (even when passing in a new url).
I see this on the first run:
...
INFO  PlaywrightCrawler: Earlier, the crawler reached the maxRequestsPerCrawl limit of 2 requests and all requests that were in progress at that time have now finished. In total, the crawler processed 5 requests and will shut down.
INFO  PlaywrightCrawler: Final request statistics: {"requestsFinished":5,"requestsFailed":0,"retryHistogram":[5],"requestAvgFailedDurationMillis":null,"requestAvgFinishedDurationMillis":13368,"requestsFinishedPerMinute":9,"requestsFailedPerMinute":0,"requestTotalDurationMillis":66838,"requestsTotal":5,"crawlerRuntimeMillis":32684}
INFO  PlaywrightCrawler: Finished! Total 5 requests: 5 succeeded, 0 failed. {"terminal":true}
...
INFO  PlaywrightCrawler: Earlier, the crawler reached the maxRequestsPerCrawl limit of 2 requests and all requests that were in progress at that time have now finished. In total, the crawler processed 5 requests and will shut down.
INFO  PlaywrightCrawler: Final request statistics: {"requestsFinished":5,"requestsFailed":0,"retryHistogram":[5],"requestAvgFailedDurationMillis":null,"requestAvgFinishedDurationMillis":13368,"requestsFinishedPerMinute":9,"requestsFailedPerMinute":0,"requestTotalDurationMillis":66838,"requestsTotal":5,"crawlerRuntimeMillis":32684}
INFO  PlaywrightCrawler: Finished! Total 5 requests: 5 succeeded, 0 failed. {"terminal":true}

Then this on the second:
INFO  PlaywrightCrawler: Starting the crawler.
INFO  PlaywrightCrawler: Crawler reached the maxRequestsPerCrawl limit of 2 requests and will shut down soon. Requests that are in progress will be allowed to finish.
INFO  PlaywrightCrawler: Final request statistics: {"requestsFinished":0,"requestsFailed":0,...
INFO  PlaywrightCrawler: Starting the crawler.
INFO  PlaywrightCrawler: Crawler reached the maxRequestsPerCrawl limit of 2 requests and will shut down soon. Requests that are in progress will be allowed to finish.
INFO  PlaywrightCrawler: Final request statistics: {"requestsFinished":0,"requestsFailed":0,...


I have a function that takes a single string value (
step_id
step_id
) and passes that value into a function that returns the request handler.
export function crawler<T>(step_id: string) {
  const playwright_crawler = new PlaywrightCrawler({
    maxRequestsPerCrawl: 2,
    requestHandler: create_crawlee_rec_handler(step_id),
  });
  return playwright_crawler;
}
export function crawler<T>(step_id: string) {
  const playwright_crawler = new PlaywrightCrawler({
    maxRequestsPerCrawl: 2,
    requestHandler: create_crawlee_rec_handler(step_id),
  });
  return playwright_crawler;
}


This function is imported and called as such:
const crawlerInstance = crawler(`${step.id}`);
    await crawlerInstance.run([href]);
const crawlerInstance = crawler(`${step.id}`);
    await crawlerInstance.run([href]);


If I don't curry the step_id into the request handler, the second run works just fine. Maybe there is another way to get my step_id value into the scope of the request handler?
Thanks in advance for any advice.
Apify & Crawlee banner
Apify & CrawleeJoin
This is the official developer community of Apify and Crawlee.
13,739Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Recent Announcements
ellativity

**The Apify $1M Challenge is over!** For everyone who joined yesterday’s Award Ceremony livestream for the Apify $1M Challenge, thank you for your enthusiastic drumrolls in the chat and positive vibes. We were really feeling the excitement and celebratory mood! If you missed the stream or just want to rewatch the key moments again, here’s the replay link https://www.youtube.com/watch?v=eEDV-5X43Gg (ngl, the replay is not the same without your live chat) And, if you didn’t check the email that should have landed in your inboxes, we’d love to hear about your experience of participating in the Apify $1M Challenge. **<a:alerthulk:1468892073917939713> Win one of five $100 Visa gift cards by completing the end-of-challenge survey here: https://apify.typeform.com/to/mjoMaZqD** Thank you again to everyone who participated in any capacity. The past 3 months have been a wild ride and we feel so grateful to have been on this adventure with y’all. We mean every word when we say how much you’ve impressed us. Thank you all from the bottom of our hearts. <a:keanuthanks:1430839059655426068> Saurav and Ella xoxo PS - if you just want to jump to the spoilers, a full list of winners is available at https://apify.com/challenge 🏆

ellativity · 4d ago

ellativity

**You are invited** ... to celebrate all the achievements of the Apify $1M Challenge with us on Wednesday, February 4 at **8 AM PT / 11 AM ET / 4 PM GMT / 5 PM CET / 9:30 PM IST / 12 AM +1d CST** We will be announcing winners of the Grand Prizes, as well as regional winners and much more, with especially good news for all participating developers. 🏆 We look forward to sharing with you all! 🎉 More info here: https://luma.com/6c1493t0

ellativity · 2w ago

ellativity

Hi @everyone 👋 I'm hanging out in https://discord.com/channels/801163717915574323/1430491198145167371 for the next 45 min, if you want to discuss the end of the challenge or anything else.

ellativity · 2w ago

Similar Threads

How to make a request within a handler
ill-bronzeIill-bronze / crawlee-js
3y ago
PlayWrightCrawler new request results are bleeding into old requests. RequestQueue issue?
primary-violetPprimary-violet / crawlee-js
4y ago
Retire session after request handler timed out
hurt-tomatoHhurt-tomato / crawlee-js
3y ago
How to catch/access the errors in the handler function for failed request
ill-bronzeIill-bronze / crawlee-js
3y ago