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

introduce CLOSESPIDER_TIMEOUT_NO_ITEM in CloseSpider #5979

Merged
merged 3 commits into from Jul 28, 2023

Conversation

BurnzZ
Copy link
Member

@BurnzZ BurnzZ commented Jul 18, 2023

Motivation: Sometimes spiders still keep running without producing any items. This could be due to a variety of reasons like poor dupe URL filtration, bad crawling strategy, etc.

Proposal: Auto-close the spider if it hasn't produced any items in the past number of seconds.

@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Merging #5979 (a6ccbc3) into master (8055a94) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

❗ Current head a6ccbc3 differs from pull request most recent head 368ab29. Consider uploading reports for the commit 368ab29 to get more accurate results

@@            Coverage Diff             @@
##           master    #5979      +/-   ##
==========================================
- Coverage   89.19%   89.15%   -0.04%     
==========================================
  Files         162      162              
  Lines       11287    11309      +22     
  Branches     1833     1836       +3     
==========================================
+ Hits        10067    10083      +16     
- Misses        928      933       +5     
- Partials      292      293       +1     
Impacted Files Coverage Δ
scrapy/extensions/closespider.py 96.82% <100.00%> (+1.70%) ⬆️

... and 2 files with indirect coverage changes

self.items_in_period += 1

def _count_items_produced(self, spider):
if self.items_in_period >= 1:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought of exposing this but I think it's better to keep it simple for now. Users can opt to override this method anyway if they need a customized condition of when to close the spider.

Copy link
Member

@kmike kmike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! If needed, we can add the "items in period" setting later.

@kmike kmike added this to the Scrapy 2.10 milestone Jul 27, 2023
@wRAR wRAR merged commit bddbbc5 into scrapy:master Jul 28, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants