Skip to content

Commit

Permalink
Improvements to file storage
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Mar 3, 2020
1 parent 02315f9 commit 2335b7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions thingsboard_gateway/storage/event_storage_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def write(self, msg):
if self.current_file_records_count[0] - self.previous_file_records_count[0] >= self.settings.get_max_records_between_fsync():
self.previous_file_records_count = self.current_file_records_count[:]
self.buffered_writer.flush()
try:
if self.buffered_writer is not None and self.buffered_writer.closed is False:
self.buffered_writer.close()
except IOError as e:
log.warning("Failed to close buffered writer! %s", e)
except IOError as e:
log.warning("Failed to update data file![%s]\n%s", self.current_file, e)

Expand Down
4 changes: 3 additions & 1 deletion thingsboard_gateway/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from thingsboard_gateway.storage.memory_event_storage import MemoryEventStorage
from thingsboard_gateway.storage.file_event_storage import FileEventStorage
from random import randint
from time import sleep
import logging
import os
import base64
Expand Down Expand Up @@ -104,10 +105,11 @@ def test_file_storage(self):
"max_read_records_count": 10,
"no_records_sleep_interval": 5000
}
storage = FileEventStorage('storage', storage_test_config)
storage = FileEventStorage(storage_test_config)

for test_value in range(test_size * 10):
storage.put(str(test_value))
sleep(.01)

result = []
for _ in range(test_size):
Expand Down

0 comments on commit 2335b7d

Please sign in to comment.