Skip to content

Commit

Permalink
Merge pull request #376 from FNNDSC/tail-logs-keep-nonascii
Browse files Browse the repository at this point in the history
Fix truncation conditional length, keep non-ascii chars
  • Loading branch information
jennydaman authored Mar 20, 2022
2 parents dc4794f + 113b3d6 commit 2d63355
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions chris_backend/plugininstances/services/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@

class PluginInstanceManager(object):

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

def __init__(self, plugin_instance):

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

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

if len(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)
# truncate logs, assuming worst case where every character needs to be escaped
if len(logs) > 1800:
d_jobStatusSummary['compute']['return']['job_logs'] = logs[-1800:]
# PostgreSQL allows UTF-8, supports emojis, chinese, etc.
return json.dumps(d_jobStatusSummary, ensure_ascii=False)

0 comments on commit 2d63355

Please sign in to comment.