File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
spidermon/contrib/stats/statscollectors Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ def _stats_location(self, spider):
1414 spider_name = get_spider_name (spider )
1515 return os .path .join (statsdir , f"{ spider_name } _stats_history" )
1616
17- def open_spider (self , spider ):
17+ def open_spider (self , spider = None ):
18+ # Support both new API (spider=None, get from crawler) and old API (spider passed)
19+ if spider is None :
20+ spider = self ._crawler .spider
1821 stats_location = self ._stats_location (spider )
1922
2023 max_stored_stats = spider .crawler .settings .getint (
@@ -32,7 +35,9 @@ def open_spider(self, spider):
3235
3336 spider .stats_history = _stats_history
3437
35- def _persist_stats (self , stats , spider ):
38+ def _persist_stats (self , stats ):
39+ # Parent class calls this with only stats parameter, spider available via crawler
40+ spider = self ._crawler .spider
3641 stats_location = self ._stats_location (spider )
3742
3843 spider .stats_history .appendleft (self ._stats )
Original file line number Diff line number Diff line change @@ -25,8 +25,12 @@ def _open_collection(self, spider):
2525 store = collections .get_store (stats_location )
2626 return store
2727
28- def open_spider (self , spider ):
29- super ().open_spider (spider )
28+ def open_spider (self , spider = None ):
29+ # Support both new API (spider=None, get from crawler) and old API (spider passed)
30+ if spider is None :
31+ spider = self ._crawler .spider
32+ # Parent class no longer accepts spider parameter
33+ super ().open_spider ()
3034 self .store = self ._open_collection (spider )
3135 # note that the _open_collection method does not error if collection does not exist yet
3236 if self .store is None :
@@ -45,7 +49,9 @@ def open_spider(self, spider):
4549
4650 spider .stats_history = stats_history
4751
48- def _persist_stats (self , stats , spider ):
52+ def _persist_stats (self , stats ):
53+ # Parent class calls this with only stats parameter, spider available via crawler
54+ spider = self ._crawler .spider
4955 if self .store is None :
5056 return
5157 stats_history = spider .stats_history
You can’t perform that action at this time.
0 commit comments