Skip to content

Commit fde9264

Browse files
only change the private method
1 parent a57c841 commit fde9264

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

stitchclient/client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def moving_average_bytes_per_record(self):
112112
num_records += stats.num_records
113113
num_bytes += stats.num_bytes
114114

115-
return num_bytes // num_records if num_records else None
115+
return num_bytes // num_records
116116

117117
def push(self, message, callback_arg=None):
118118
"""message should be a dict recognized by the Stitch Import API.
@@ -151,16 +151,20 @@ def _take_batch(self, min_records):
151151
self._buffer.clear()
152152
return result
153153

154+
154155
def _send_batch(self, batch):
155156
for body, callback_args in partition_batch(batch, self.max_batch_size_bytes):
156157
self._send(body, callback_args)
157158

158-
if self.moving_average_bytes_per_record():
159+
try:
160+
moving_average = self.moving_average_bytes_per_record()
159161
self.target_messages_per_batch = \
160162
min(self.max_messages_per_batch,
161-
0.8 * (self.max_batch_size_bytes / self.moving_average_bytes_per_record()))
162-
else:
163-
self.target_messages_per_batch = self.max_messages_per_batch
163+
0.8 * (self.max_batch_size_bytes / moving_average))
164+
except ZeroDivisionError:
165+
# Handle the case where there are no records
166+
pass
167+
164168

165169
def _stitch_request(self, body):
166170
headers = {'Authorization': 'Bearer {}'.format(self.token),

0 commit comments

Comments
 (0)