From 26e4249f5c8c50060137d97c8c0dab2655f076da Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Fri, 7 Jun 2024 21:23:49 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=83=20Sync=20Hub=20v0.7=20-=20Devices?= =?UTF-8?q?=20working?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/plugins/sync/config.json | 2 +- front/plugins/sync/sync.py | 15 ++++++++++----- server/plugin_utils.py | 5 +---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/front/plugins/sync/config.json b/front/plugins/sync/config.json index 0f67bff4..3433c90a 100755 --- a/front/plugins/sync/config.json +++ b/front/plugins/sync/config.json @@ -514,7 +514,7 @@ "name" : "SYNC_instance_type", "value": "hub" }, - "default_value":"0 2 * * 3", + "default_value":"*/5 * * * *", "options": [], "localized": ["name", "description"], "name" : [{ diff --git a/front/plugins/sync/sync.py b/front/plugins/sync/sync.py index 0b0449d8..5c114767 100755 --- a/front/plugins/sync/sync.py +++ b/front/plugins/sync/sync.py @@ -44,7 +44,6 @@ def main(): # Get all plugin configurations all_plugins = get_plugins_configs() - mylog('verbose', [f'[{pluginName}] DEBUG {len(all_plugins)}']) mylog('verbose', [f'[{pluginName}] plugins_to_sync {plugins_to_sync}']) # Plugins processing @@ -104,6 +103,8 @@ def main(): unique_mac_addresses = set() device_data = [] + mylog('verbose', [f'[{pluginName}] Devices files to process: "{files_to_process}"']) + for file_path in files_to_process: # only process received .log files, skipping the one logging the progress of this plugin @@ -112,8 +113,8 @@ def main(): # Store e.g. Node_1 from last_result.encoded.Node_1.1.log tmp_SyncHubNodeName = '' - if len(filename.split('.')) > 3: - tmp_SyncHubNodeName = filename.split('.')[2] + if len(file_path.split('.')) > 3: + tmp_SyncHubNodeName = file_path.split('.')[2] with open(file_path, 'r') as f: data = json.load(f) @@ -131,10 +132,14 @@ def main(): # Filter out existing devices new_devices = [device for device in device_data if device['dev_MAC'] not in existing_mac_addresses] + # Remove 'rowid' key if it exists + for device in new_devices: + device.pop('rowid', None) + # Prepare the insert statement if new_devices: - columns = ', '.join(new_devices[0].keys()) - placeholders = ', '.join('?' for _ in new_devices[0]) + columns = ', '.join(k for k in new_devices[0].keys() if k != 'rowid') + placeholders = ', '.join('?' for k in new_devices[0] if k != 'rowid') sql = f'INSERT INTO Devices ({columns}) VALUES ({placeholders})' # Extract values for the new devices diff --git a/server/plugin_utils.py b/server/plugin_utils.py index 2ad0e393..f0774edc 100755 --- a/server/plugin_utils.py +++ b/server/plugin_utils.py @@ -285,11 +285,8 @@ def decode_and_rename_files(file_dir, file_prefix): files_to_process.append(new_filename) - elif filename == 'last_result.log': - files_to_process.append(filename) else: - # Skipping decoded and other files - continue + files_to_process.append(filename) else: mylog('debug', [f'[Plugins] The file {file_path} does not exist'])