MCPcopy
hub / github.com/scrapy/scrapy / _close_slot

Method _close_slot

scrapy/extensions/feedexport.py:545–577  ·  view source on GitHub ↗
(self, slot: FeedSlot, spider: Spider)

Source from the content-addressed store, hash-verified

543 return slot_.file
544
545 async def _close_slot(self, slot: FeedSlot, spider: Spider) -> None:
546
547 if slot.itemcount:
548 # Normal case
549 slot.finish_exporting()
550 elif slot.store_empty and slot.batch_id == 1:
551 # Need to store the empty file
552 slot.start_exporting()
553 slot.finish_exporting()
554 else:
555 # In this case, the file is not stored, so no processing is required.
556 return
557
558 logmsg = f"{slot.format} feed ({slot.itemcount} items) in: {slot.uri}"
559 slot_type = type(slot.storage).__name__
560 assert self.crawler.stats
561 try:
562 await ensure_awaitable(slot.storage.store(self._get_file(slot)))
563 except Exception:
564 logger.error(
565 "Error storing %s",
566 logmsg,
567 exc_info=True,
568 extra={"spider": spider},
569 )
570 self.crawler.stats.inc_value(f"feedexport/failed_count/{slot_type}")
571 else:
572 logger.info("Stored %s", logmsg, extra={"spider": spider})
573 self.crawler.stats.inc_value(f"feedexport/success_count/{slot_type}")
574
575 await self.crawler.signals.send_catch_log_async(
576 signals.feed_slot_closed, slot=slot
577 )
578
579 def _start_new_batch(
580 self,

Callers 2

close_spiderMethod · 0.95
item_scrapedMethod · 0.95

Calls 9

_get_fileMethod · 0.95
ensure_awaitableFunction · 0.90
errorMethod · 0.80
infoMethod · 0.80
send_catch_log_asyncMethod · 0.80
finish_exportingMethod · 0.45
start_exportingMethod · 0.45
storeMethod · 0.45
inc_valueMethod · 0.45

Tested by

no test coverage detected