Skip to content

Commit 0357925

Browse files
committed
Stopped sending empty payloads
- fixes snowplow#106
1 parent fa06b77 commit 0357925

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Allowed a single Tracker instance to send events to multiple Emitters (#91)
99
Started passing a list of dictionaries to the on_failure callback for POST requests (#104)
1010
Made the "name" argument of track_screen_view optional (#103)
1111
Made all tracker methods chainable (#105)
12-
Stopped sending empty payloads (#106) (TODO)
12+
Stopped sending empty payloads (#106)
1313

1414
Version 0.4.0 (2014-06-10)
1515
--------------------------

snowplow_tracker/emitters.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,18 @@ def flush(self):
147147
Sends all events in the buffer to the collector.
148148
"""
149149
if self.method == "post":
150-
data = json.dumps({
151-
"schema": PAYLOAD_DATA_SCHEMA,
152-
"data": self.buffer
153-
})
154-
temp_buffer = self.buffer
155-
self.buffer = []
156-
status_code = self.http_post(data).status_code
157-
if status_code == 200 and self.on_success is not None:
158-
self.on_success(len(temp_buffer))
159-
elif self.on_failure is not None:
160-
self.on_failure(0, temp_buffer)
150+
if self.buffer:
151+
data = json.dumps({
152+
"schema": PAYLOAD_DATA_SCHEMA,
153+
"data": self.buffer
154+
})
155+
temp_buffer = self.buffer
156+
self.buffer = []
157+
status_code = self.http_post(data).status_code
158+
if status_code == 200 and self.on_success is not None:
159+
self.on_success(len(temp_buffer))
160+
elif self.on_failure is not None:
161+
self.on_failure(0, temp_buffer)
161162

162163
elif self.method == "get":
163164
success_count = 0

0 commit comments

Comments
 (0)