3333logger .setLevel (logging .DEBUG )
3434
3535DEFAULT_MAX_LENGTH = 10
36+ THREAD_TIMEOUT = 10
3637
3738new_contract ("protocol" , lambda x : x == "http" or x == "https" )
3839
@@ -71,7 +72,7 @@ def __init__(self, endpoint, protocol="http", port=None, method="get", buffer_si
7172 :param method: The HTTP request method
7273 :type method: method
7374 :param buffer_size: The maximum number of queued events before the buffer is flushed. Default is 10.
74- :type buffer_size: string | None
75+ :type buffer_size: int | None
7576 :param on_success: Callback executed after every HTTP request in a flush has status code 200
7677 Gets passed the number of events flushed.
7778 :type on_success: function | None
@@ -97,6 +98,8 @@ def __init__(self, endpoint, protocol="http", port=None, method="get", buffer_si
9798 self .on_success = on_success
9899 self .on_failure = on_failure
99100
101+ self .threads = []
102+
100103 @staticmethod
101104 @contract
102105 def as_collector_uri (endpoint , protocol = "http" , port = None ):
@@ -197,16 +200,25 @@ def sync_flush(self):
197200 """
198201 logger .debug ("Starting synchronous flush..." )
199202 result = Consumer .flush (self )
203+ for t in self .threads :
204+ t .join (THREAD_TIMEOUT )
200205 logger .debug ("Finished synchrous flush" )
201206 return result
202207
208+
203209class AsyncConsumer (Consumer ):
204210 """
205211 Uses threads to send HTTP requests asynchronously
206212 """
207213 def flush (self ):
214+ """
215+ Removes all dead threads, then creates a new thread which
216+ excecutes the flush method of the base Consumer class
217+ """
218+ self .threads = [t for t in self .threads if t .isAlive ()]
208219 logger .debug ("Flushing thread running..." )
209220 t = threading .Thread (target = super (AsyncConsumer , self ).flush )
221+ self .threads .append (t )
210222 t .start ()
211223
212224
0 commit comments