mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-02-19 02:34:20 -05:00
stats: Make get_timer return a stub object if Graphite disabled.
This saves us from having to do explicit checks for whether or not the timer exists everywhere we use them.
This commit is contained in:
@@ -85,7 +85,7 @@ class Stats:
|
||||
if self.connection:
|
||||
return self.statsd.timer.Timer(name, self.connection)
|
||||
else:
|
||||
return None
|
||||
return utils.SimpleSillyStub()
|
||||
|
||||
def transact(self, action, service_time_sec):
|
||||
timer = self.get_timer('service_time')
|
||||
|
||||
@@ -1310,6 +1310,17 @@ class Bomb(object):
|
||||
def __repr__(cls):
|
||||
raise Hell()
|
||||
|
||||
class SimpleSillyStub(object):
|
||||
"""A simple stub object that does nothing when you call its methods."""
|
||||
def __nonzero__(self):
|
||||
return False
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self.stub
|
||||
|
||||
def stub(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def strordict_fullname(item, key='fullname'):
|
||||
"""Sometimes we migrate AMQP queues from simple strings to pickled
|
||||
dictionaries. During the migratory period there may be items in
|
||||
|
||||
Reference in New Issue
Block a user