Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

added domain_stats parameter to stats_domain_closed signal

Pablo Hoffmanc3427e075c3b
diff --git a/docs/topics/stats.rst b/docs/topics/stats.rst
index 4cb9bf676..4f47342c0 100644
--- a/docs/topics/stats.rst
+++ b/docs/topics/stats.rst
@@ -281,7 +281,7 @@ functionality:
:type reason: str
.. signal:: stats_domain_closed
-.. function:: stats_domain_closed(domain, reason)
+.. function:: stats_domain_closed(domain, reason, domain_stats)
Sent right after the stats domain is closed. You can use this signal to
collect resources.
@@ -289,6 +289,9 @@ functionality:
:param domain: the stats domain just closed
:type domain: str
- :param reason: the reason why the domain is being closed. See
+ :param reason: the reason why the domain was closed. See
:signal:`domain_closed` signal for more info.
:type reason: str
+
+ :param domain_stats: the stats of the domain just closed.
+ :type reason: dict
diff --git a/scrapy/contrib/statsmailer.py b/scrapy/contrib/statsmailer.py
index ced8d6918..4a580bf5c 100644
--- a/scrapy/contrib/statsmailer.py
+++ b/scrapy/contrib/statsmailer.py
@@ -17,12 +17,12 @@ class StatsMailer(object):
self.recipients = settings.getlist("STATSMAILER_RCPTS")
if not self.recipients:
raise NotConfigured
- dispatcher.connect(self.send_stats, signal=signals.stats_domain_closing)
+ dispatcher.connect(self.stats_domain_closed, signal=signals.stats_domain_closed)
- def send_stats(self, domain):
+ def stats_domain_closed(self, domain, domain_stats):
mail = MailSender()
body = "Global stats\n\n"
body += "\n".join("%-50s : %s" % i for i in stats.get_stats().items())
body += "\n\n%s stats\n\n" % domain
- body += "\n".join("%-50s : %s" % i for i in stats.get_stats(domain).items())
+ body += "\n".join("%-50s : %s" % i for i in domain_stats.items())
mail.send(self.recipients, "Scrapy stats for: %s" % domain, body)
diff --git a/scrapy/stats/collector/__init__.py b/scrapy/stats/collector/__init__.py
index 8a1fa26e9..c145077be 100644
--- a/scrapy/stats/collector/__init__.py
+++ b/scrapy/stats/collector/__init__.py
@@ -51,8 +51,9 @@ class StatsCollector(object):
if self._dump:
log.msg("Dumping stats:\n" + pprint.pformat(self.get_stats(domain)), \
domain=domain)
- del self._stats[domain]
- signals.send_catch_log(stats_domain_closed, domain=domain, reason=reason)
+ stats = self._stats.pop(domain)
+ signals.send_catch_log(stats_domain_closed, domain=domain, reason=reason, \
+ domain_stats=stats)
def engine_stopped(self):
if self._dump: