Skip to content

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

SimpledbStatsCollector: moved domain creation to constructor

Pablo Hoffman92b746d866d2
diff --git a/docs/topics/stats.rst b/docs/topics/stats.rst
index 3622c1136..4cb9bf676 100644
--- a/docs/topics/stats.rst
+++ b/docs/topics/stats.rst
@@ -201,7 +201,8 @@ SimpledbStatsCollector
A Stats collector which persists stats to `Amazon SimpleDB`_, using one
SimpleDB item per scraping run (ie. it keeps history of all scraping runs).
The data is persisted to the SimpleDB domain specified by the
- :setting:`STATS_SDB_DOMAIN` setting.
+ :setting:`STATS_SDB_DOMAIN` setting. The domain will be created if it
+ doesn't exist.
In addition to the existing stats keys the following keys are added at
persitance time:
diff --git a/scrapy/stats/collector/simpledb.py b/scrapy/stats/collector/simpledb.py
index 7c2955323..cfe87bb84 100644
--- a/scrapy/stats/collector/simpledb.py
+++ b/scrapy/stats/collector/simpledb.py
@@ -20,6 +20,8 @@ class SimpledbStatsCollector(StatsCollector):
super(SimpledbStatsCollector, self).__init__()
self._sdbdomain = settings['STATS_SDB_DOMAIN']
self._async = settings.getbool('STATS_SDB_ASYNC')
+ sdb = boto.connect_sdb()
+ sdb.create_domain(self._sdbdomain)
def close_domain(self, domain, reason):
if self._sdbdomain:
@@ -39,7 +41,6 @@ class SimpledbStatsCollector(StatsCollector):
sdb_item['domain'] = domain
sdb_item['timestamp'] = self._to_sdb_value(ts)
sdb = boto.connect_sdb()
- sdb.create_domain(self._sdbdomain)
sdb.batch_put_attributes(self._sdbdomain, {sdb_item_id: sdb_item})
def _to_sdb_value(self, obj):