1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Added pause on creating new datafile, added some improvements

This commit is contained in:
zbeacon
2019-11-08 09:47:14 +02:00
parent e27af39c11
commit 245e4df303
4 changed files with 11 additions and 8 deletions

2
.gitignore vendored
View File

@@ -9,3 +9,5 @@ thingsboard_gateway/storage/data/
/build/
/deb_dist/
/dist/
/.mypy_cache/
/thingsboard_gateway/storage/data_out/

View File

@@ -63,7 +63,7 @@ class EventStorageReader:
if records_to_read == 0:
break
if current_line_in_file == self.settings.get_max_records_per_file():
if current_line_in_file >= self.settings.get_max_records_per_file():
next_file = self.get_next_file(self.files, self.new_pos)
if next_file is not None:
if self.buffered_reader is not None:

View File

@@ -116,13 +116,14 @@ class EventStorageWriter:
file_path = self.settings.get_data_folder_path() + prefix + filename + '.txt'
try:
file = open(file_path, 'w')
time.sleep(.01)
file.close()
return prefix + filename + '.txt'
except IOError as e:
log.error("Failed to create a new file!", e)
def get_number_of_records_in_file(self, file):
if self.current_file_records_count == 0:
if self.current_file_records_count <= 0:
try:
with open(self.settings.get_data_folder_path() + file) as f:
for i, l in enumerate(f):

View File

@@ -22,7 +22,7 @@ import os
import base64
import threading
logging.basicConfig(level=logging.DEBUG,
logging.basicConfig(level=logging.ERROR,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
@@ -94,13 +94,13 @@ class TestStorage(unittest.TestCase):
def test_file_storage(self):
test_size = 13
test_size = 5
storage_test_config = {
"data_folder_path": "thingsboard_gateway/storage/data/",
"max_files_count": 2000,
"max_records_per_file": 50,
"max_read_records_count": 12,
"max_records_per_file": 10,
"max_read_records_count": 10,
"no_records_sleep_interval": 5000
}
storage = FileEventStorage('storage', storage_test_config)
@@ -108,8 +108,8 @@ class TestStorage(unittest.TestCase):
storage_out_test_config = {
"data_folder_path": "thingsboard_gateway/storage/data_out/",
"max_files_count": 2000,
"max_records_per_file": 50,
"max_read_records_count": 12,
"max_records_per_file": 10,
"max_read_records_count": 10,
"no_records_sleep_interval": 5000
}
storage_out = FileEventStorage('storage_out', storage_out_test_config)