Skip to content

Commit

Permalink
Refactor remote logging handling into a separate function for improve…
Browse files Browse the repository at this point in the history
…d clarity and maintainability
  • Loading branch information
dkmstr committed Nov 13, 2024
1 parent 8f2a6df commit 81a1a0c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/UDSClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def fetch_transport_data(self) -> None:
if logger.getEffectiveLevel() == logging.DEBUG:
logger.exception('Get Transport Data')
self.show_error(e)
process_remote_log(self.api)

def process_waiting_tasks(self) -> None:
"""
Expand Down Expand Up @@ -245,6 +246,17 @@ def settings(group: str) -> typing.Iterator[QSettings]:
yield settings
settings.endGroup()

def process_remote_log(api: RestApi) -> None:
# Process remote logging if requested
try:
log_ticket, log_data = get_remote_log()
logger.debug('** Remote log data: %s, %s', log_ticket, len(log_data))
if log_ticket != '' and len(log_data) > 0:
logger.debug('** Sending log data: %s, %s', log_ticket, len(log_data))
api.send_log(log_ticket, log_data[-65536:]) # Limit to 64K
except Exception as e: # pylint: disable=broad-exception-caught
logger.error('** Error sending log data: %s', e)


def waiting_tasks_processor(api: RestApi) -> None:
# Wait a bit before start processing ending sequence
Expand Down Expand Up @@ -277,15 +289,7 @@ def waiting_tasks_processor(api: RestApi) -> None:

logger.debug('endScript done')

# Process remote logging if requested
try:
log_ticket, log_data = get_remote_log()
logger.debug('** Remote log data: %s, %s', log_ticket, len(log_data))
if log_ticket != '' and len(log_data) > 0:
logger.debug('** Sending log data: %s, %s', log_ticket, len(log_data))
api.send_log(log_ticket, log_data[-65536:]) # Limit to 64K
except Exception as e: # pylint: disable=broad-exception-caught
logger.error('** Error sending log data: %s', e)
process_remote_log(api)


# Ask user to approve endpoint
Expand Down

0 comments on commit 81a1a0c

Please sign in to comment.