44import threading
55from datetime import datetime , timedelta
66from mixpanel import BufferedConsumer as SynchronousBufferedConsumer
7+ from mixpanel import MixpanelException
78
89class FlushThread (threading .Thread ):
910 '''
@@ -44,18 +45,18 @@ class AsyncBufferedConsumer(SynchronousBufferedConsumer):
4445
4546 Because AsyncBufferedConsumer holds events until the `flush_after` timeout
4647 or an endpoint queue hits the size of _max_queue_size, you should call
47- flush(async=False) before you terminate any process where you have been
48+ flush(async=False) before you terminate any process where you have been
4849 using the AsyncBufferedConsumer.
4950 '''
5051
5152 # constants used in the _should_flush method
5253 ALL = "ALL"
5354 ENDPOINT = "ENDPOINT"
5455
55- def __init__ (self , flush_after = timedelta (0 , 10 ), flush_first = True , max_size = 20 ,
56+ def __init__ (self , flush_after = timedelta (0 , 10 ), flush_first = True , max_size = 20 ,
5657 events_url = None , people_url = None , * args , ** kwargs ):
5758 '''
58- Create a new instance of a AsyncBufferedConsumer class.
59+ Create a new instance of a AsyncBufferedConsumer class.
5960
6061 :param flush_after (datetime.timedelta): the time period after which
6162 the AsyncBufferedConsumer will flush the events upon receiving a
@@ -68,12 +69,12 @@ def __init__(self, flush_after=timedelta(0, 10), flush_first=True, max_size=20,
6869 :param people_url: the Mixpanel API URL that people events will be sent to
6970 '''
7071 super (AsyncBufferedConsumer , self ).__init__ (
71- max_size = max_size ,
72- events_url = events_url ,
72+ max_size = max_size ,
73+ events_url = events_url ,
7374 people_url = people_url
7475 )
7576
76- # remove the minimum max size that the SynchronousBufferedConsumer
77+ # remove the minimum max size that the SynchronousBufferedConsumer
7778 # class sets
7879 self ._max_size = max_size
7980 self .flush_after = flush_after
@@ -149,7 +150,7 @@ def send(self, endpoint, json_message):
149150 :raises: MixpanelException
150151 '''
151152 if endpoint not in self ._async_buffers :
152- raise MixpanelException ('No such endpoint "{0}". Valid endpoints are one of {1}' .format (self ._async_buffers .keys ()))
153+ raise MixpanelException ('No such endpoint "{0}". Valid endpoints are one of {1}' .format (endpoint , self ._async_buffers .keys ()))
153154
154155 buf = self ._async_buffers [endpoint ]
155156 buf .append (json_message )
@@ -175,8 +176,8 @@ def flush(self, endpoint=None, async=True):
175176 thrown will have a message property, containing the text of the message,
176177 and an endpoint property containing the endpoint that failed.
177178
178-
179- :param endpoint (str): One of 'events' or 'people, the Mixpanel endpoint
179+
180+ :param endpoint (str): One of 'events' or 'people, the Mixpanel endpoint
180181 for sending the data
181182 :param async (bool): Whether to flush the data in a seperate thread or not
182183 '''
@@ -209,7 +210,7 @@ def flush(self, endpoint=None, async=True):
209210 # event is added this second flush will be retriggered and
210211 # will complete.
211212 flushing = False
212-
213+
213214 else :
214215 self .transfer_buffers (endpoint = endpoint )
215216 self ._sync_flush (endpoint = endpoint )
@@ -226,17 +227,17 @@ def transfer_buffers(self, endpoint=None):
226227 Transfer events from the `_async_buffers` where they are stored to the
227228 `_buffers` where they will be flushed from by the flushing thread.
228229
229- :param endpoint (str): One of 'events' or 'people, the Mixpanel endpoint
230+ :param endpoint (str): One of 'events' or 'people, the Mixpanel endpoint
230231 that is about to be flushed
231232 """
232- if endpoint :
233+ if endpoint :
233234 keys = [endpoint ]
234235 else :
235236 keys = self ._async_buffers .keys ()
236237
237238 for key in keys :
238239 buf = self ._async_buffers [key ]
239- while buf :
240+ while buf :
240241 self ._buffers [key ].append (buf .pop (0 ))
241242
242243
0 commit comments