Skip to content

Commit

Permalink
Fix log overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Mar 19, 2022
1 parent 2b6e2e9 commit fd0d038
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions chris_backend/plugininstances/services/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

class PluginInstanceManager(object):

__NONASCII = re.compile(r'[^\x00-\x7F]')

def __init__(self, plugin_instance):

self.c_plugin_inst = plugin_instance
Expand Down Expand Up @@ -670,8 +672,8 @@ def _register_output_files(self, filenames):
total_size += plg_inst_file.fname.size
self.c_plugin_inst.size += total_size

@staticmethod
def get_job_status_summary(d_response=None):
@classmethod
def get_job_status_summary(cls, d_response=None):
"""
Get a job status summary JSON string from pfcon response.
"""
Expand Down Expand Up @@ -704,5 +706,15 @@ def get_job_status_summary(d_response=None):
logs = d_jobStatusSummary['compute']['return']['job_logs'] = d_c['logs']

if len(logs) > 3000:
d_jobStatusSummary['compute']['return']['job_logs'] = logs[-3000:]
# Workaround which fixes https://github.com/FNNDSC/ChRIS_ultron_backEnd/issues/364
# Better solution discussed in https://github.com/FNNDSC/ChRIS_ultron_backEnd/issues/374
#
# JSON serialization causes string to be longer than you might expect
# because of escape sequences, e.g. json.dumps('\n') -> '"\\n"'

# replace non-ASCII characters, such as emojis and Chinese characters
logs_ascii = cls.__NONASCII.sub('?', logs)

# truncate logs, assuming worst case where every character needs to be escaped
d_jobStatusSummary['compute']['return']['job_logs'] = logs_ascii[-1800:]
return json.dumps(d_jobStatusSummary)

0 comments on commit fd0d038

Please sign in to comment.