Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocking I/O in shares Parser #13

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make msg_parser async
  • Loading branch information
chris-mc1 committed Sep 3, 2024
commit ea05424cb16cee4d70bd3e609f50c620cc21587f
4 changes: 2 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ async def ws_connect(self):
if sub_channel not in self.mqtt_history:
self.logger.info(f'Create config for {sub_channel}')
self.mqtt_history[sub_channel] = (time.time() - self.scan_interval)
msg_parser(self, msg_data, create_config=True)
await msg_parser(self, msg_data, create_config=True)

# Parse content
if self.scan_interval <= (time.time() - self.mqtt_history.get(sub_channel, time.time())):
self.logger.info(f'Parse data for {sub_channel}')
self.mqtt_history[sub_channel] = time.time()
msg_parser(self, msg_data, create_config=False)
await msg_parser(self, msg_data, create_config=False)

except (httpx.ConnectTimeout, httpx.ConnectError):
self.logger.error('Failed to connect to unraid due to a timeout or connection issue...')
Expand Down
20 changes: 10 additions & 10 deletions app/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
from humanfriendly import parse_size


def default(self, msg_data, create_config):
async def default(self, msg_data, create_config):
pass


def session(self, msg_data, create_config):
async def session(self, msg_data, create_config):
self.csrf_token = msg_data


def cpuload(self, msg_data, create_config):
async def cpuload(self, msg_data, create_config):
prefs = Preferences(msg_data)
state_value = int(prefs.as_dict()['cpu']['host'])

Expand All @@ -28,7 +28,7 @@ def cpuload(self, msg_data, create_config):
self.mqtt_publish(payload, 'sensor', state_value, create_config=create_config)


def disks(self, msg_data, create_config):
async def disks(self, msg_data, create_config):
prefs = Preferences(msg_data)
disks = prefs.as_dict()

Expand Down Expand Up @@ -57,7 +57,7 @@ def disks(self, msg_data, create_config):
self.mqtt_publish(payload, 'sensor', disk_temp, json_attributes, create_config=create_config, retain=True)


def shares(self, msg_data, create_config):
async def shares(self, msg_data, create_config):
prefs = Preferences(msg_data)
shares = prefs.as_dict()

Expand Down Expand Up @@ -169,7 +169,7 @@ def shares(self, msg_data, create_config):
self.mqtt_publish(payload, 'sensor', share_used_pct, json_attributes, create_config=create_config, retain=True)


def temperature(self, msg_data, create_config):
async def temperature(self, msg_data, create_config):
tree = etree.HTML(msg_data)
sensors = tree.xpath('.//span[@title]')

Expand Down Expand Up @@ -205,7 +205,7 @@ def temperature(self, msg_data, create_config):
self.mqtt_publish(payload, 'sensor', device_value, create_config=create_config)


def update1(self, msg_data, create_config):
async def update1(self, msg_data, create_config):
memory_categories = ['RAM', 'Flash', 'Log', 'Docker']
for (memory_name, memory_usage) in zip(memory_categories, re.findall(re.compile(r'(\d+%)'), msg_data)):
memory_value = ''.join(c for c in memory_usage if c.isdigit())
Expand Down Expand Up @@ -240,7 +240,7 @@ def update1(self, msg_data, create_config):
self.mqtt_publish(payload, 'sensor', fan_value, create_config=create_config)


def update3(self, msg_data, create_config):
async def update3(self, msg_data, create_config):
network_download = 0
network_upload = 0

Expand Down Expand Up @@ -272,7 +272,7 @@ def update3(self, msg_data, create_config):
self.mqtt_publish(payload_upload, 'sensor', network_upload, create_config=create_config)


def parity(self, msg_data, create_config):
async def parity(self, msg_data, create_config):
data = msg_data.split(';')

if len(data) < 5:
Expand Down Expand Up @@ -303,7 +303,7 @@ def parity(self, msg_data, create_config):
self.mqtt_publish(payload, 'sensor', state_value, json_attributes, create_config=create_config)


def var(self, msg_data, create_config):
async def var(self, msg_data, create_config):
msg_data = f'[var]\n{msg_data}'
prefs = Preferences(msg_data)
var = prefs.as_dict()
Expand Down