Permalink
Browse files

restored stats_spider_{opened,closing,closed} signals in backwards co…

…mpatibility mode
  • Loading branch information...
1 parent 81ed2d2 commit 9685c24059a1eb95216dcab8f76805c8c0025a60 @pablohoffman pablohoffman committed Sep 14, 2012
Showing with 9 additions and 2 deletions.
  1. +1 −1 docs/news.rst
  2. +3 −1 scrapy/core/engine.py
  3. +4 −0 scrapy/signals.py
  4. +1 −0 scrapy/tests/test_engine.py
View
@@ -6,7 +6,7 @@ Release notes
Scrapy changes:
-- major Stats Collection refactoring: removed separation of global/per-spider stats, removed stats-related signals (``stats_spider_opened``, etc). Stats are much simpler now, backwards compatibility is kept on the Stats Collector API.
+- major Stats Collection refactoring: removed separation of global/per-spider stats, removed stats-related signals (``stats_spider_opened``, etc). Stats are much simpler now, backwards compatibility is kept on the Stats Collector API and signals.
- added :meth:`~scrapy.contrib.spidermiddleware.SpiderMiddleware.process_start_requests` method to spider middlewares
- dropped Signals singleton. Signals should now be accesed through the Crawler.signals attribute. See the signals documentation for more info.
- dropped Signals singleton. Signals should now be accesed through the Crawler.signals attribute. See the signals documentation for more info.
View
@@ -262,8 +262,10 @@ def close_spider(self, spider, reason='cancelled'):
dfd.addBoth(lambda _: slot.scheduler.close(reason))
dfd.addErrback(log.err, spider=spider)
+ # XXX: spider_stats argument was added for backwards compatibility with
+ # stats collection refactoring added in 0.15. it should be removed in 0.17.
dfd.addBoth(lambda _: self.signals.send_catch_log_deferred(signal=signals.spider_closed, \
- spider=spider, reason=reason))
+ spider=spider, reason=reason, spider_stats=self.crawler.stats.get_stats()))
dfd.addErrback(log.err, spider=spider)
dfd.addBoth(lambda _: self.crawler.stats.close_spider(spider, reason=reason))
View
@@ -17,4 +17,8 @@
item_scraped = object()
item_dropped = object()
+stats_spider_opened = spider_opened
+stats_spider_closing = spider_closed
+stats_spider_closed = spider_closed
+
item_passed = item_scraped # for backwards compatibility
@@ -197,6 +197,7 @@ def _assert_signals_catched(self):
self.run.signals_catched[signals.spider_opened])
self.assertEqual({'spider': self.run.spider},
self.run.signals_catched[signals.spider_idle])
+ self.run.signals_catched[signals.spider_closed].pop('spider_stats', None) # XXX: remove for scrapy 0.17
self.assertEqual({'spider': self.run.spider, 'reason': 'finished'},
self.run.signals_catched[signals.spider_closed])

0 comments on commit 9685c24

Please sign in to comment.