Skip to content

Commit 0cb6107

Browse files
committed
rename functions for consistency
We find the same pattern with buffer_log and flush: a sync version and a version distributed to a thread pool. This commit harmonizes namings: - schedule_flush_sync => flush_with_lock - try_lock_and_do_flush_request => flush_sync
1 parent 4968bca commit 0cb6107

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

logdna/logdna.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,20 @@ def buffer_log_sync(self, message):
122122
self._lock.release()
123123

124124
def flush(self):
125-
self.schedule_flush_sync()
125+
self.flush_with_lock()
126126

127-
def schedule_flush_sync(self, should_block=False):
127+
def flush_with_lock(self, should_block=False):
128128
if self.request_thread_pool:
129129
try:
130130
self.request_thread_pool.submit(
131-
self.try_lock_and_do_flush_request, should_block)
131+
self.flush_sync, should_block)
132132
except RuntimeError:
133-
self.try_lock_and_do_flush_request(should_block)
133+
self.flush_sync(should_block)
134134
except Exception as e:
135135
self.internalLogger.debug(
136136
'Error in calling try_lock_and_do_flush_request: %s', e)
137137

138-
def try_lock_and_do_flush_request(self, should_block=False):
138+
def flush_sync(self, should_block=False):
139139
local_buf = []
140140
if self._lock.acquire(blocking=should_block):
141141
if not self.buf:
@@ -342,7 +342,7 @@ def close(self):
342342
# application exiting and because the probability of this
343343
# introducing a noticeable delay is very low because close() is only
344344
# called when the logger and application are shutting down.
345-
self.schedule_flush_sync(should_block=True)
345+
self.flush_with_lock(should_block=True)
346346

347347
# Finally, shut down the thread pool that was used to send the log
348348
# messages to the server. We can assume at this point that all log

tests/test_logger.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_emit(self):
140140
handler.buffer_log.assert_called_once_with(sample_message)
141141

142142
@mock.patch('time.time', unittest.mock.MagicMock(return_value=now))
143-
def test_try_lock_and_do_flush_request(self):
143+
def test_flush_sync(self):
144144
with patch('requests.post') as post_mock:
145145
handler = LogDNAHandler(LOGDNA_API_KEY, sample_options)
146146
r = requests.Response()
@@ -150,7 +150,7 @@ def test_try_lock_and_do_flush_request(self):
150150
sample_message['timestamp'] = unittest.mock.ANY
151151
handler.buf = [sample_message]
152152
test_buf = handler.buf.copy()
153-
handler.try_lock_and_do_flush_request()
153+
handler.flush_sync()
154154
post_mock.assert_called_with(
155155
url=handler.url,
156156
json={
@@ -255,11 +255,11 @@ def test_close(self):
255255
handler = LogDNAHandler(LOGDNA_API_KEY, sample_options)
256256
close_flusher_mock = unittest.mock.Mock()
257257
close_flusher_mock.side_effect = handler.close_flusher
258-
handler.schedule_flush_sync = unittest.mock.Mock()
258+
handler.flush_with_lock = unittest.mock.Mock()
259259
handler.close_flusher = close_flusher_mock
260260
handler.close()
261261
handler.close_flusher.assert_called_once_with()
262-
handler.schedule_flush_sync.assert_called_once_with(
262+
handler.flush_with_lock.assert_called_once_with(
263263
should_block=True)
264264
self.assertIsNone(handler.worker_thread_pool)
265265
self.assertIsNone(handler.request_thread_pool)

0 commit comments

Comments
 (0)