Skip to content

Commit 2d63355

Browse files
authored
Merge pull request #376 from FNNDSC/tail-logs-keep-nonascii
Fix truncation conditional length, keep non-ascii chars
2 parents dc4794f + 113b3d6 commit 2d63355

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

chris_backend/plugininstances/services/manager.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070

7171
class PluginInstanceManager(object):
7272

73-
__NONASCII = re.compile(r'[^\x00-\x7F]')
74-
7573
def __init__(self, plugin_instance):
7674

7775
self.c_plugin_inst = plugin_instance
@@ -672,8 +670,8 @@ def _register_output_files(self, filenames):
672670
total_size += plg_inst_file.fname.size
673671
self.c_plugin_inst.size += total_size
674672

675-
@classmethod
676-
def get_job_status_summary(cls, d_response=None):
673+
@staticmethod
674+
def get_job_status_summary(d_response=None):
677675
"""
678676
Get a job status summary JSON string from pfcon response.
679677
"""
@@ -705,16 +703,8 @@ def get_job_status_summary(cls, d_response=None):
705703
d_jobStatusSummary['compute']['return']['job_status'] = d_c['status']
706704
logs = d_jobStatusSummary['compute']['return']['job_logs'] = d_c['logs']
707705

708-
if len(logs) > 3000:
709-
# Workaround which fixes https://github.com/FNNDSC/ChRIS_ultron_backEnd/issues/364
710-
# Better solution discussed in https://github.com/FNNDSC/ChRIS_ultron_backEnd/issues/374
711-
#
712-
# JSON serialization causes string to be longer than you might expect
713-
# because of escape sequences, e.g. json.dumps('\n') -> '"\\n"'
714-
715-
# replace non-ASCII characters, such as emojis and Chinese characters
716-
logs_ascii = cls.__NONASCII.sub('?', logs)
717-
718-
# truncate logs, assuming worst case where every character needs to be escaped
719-
d_jobStatusSummary['compute']['return']['job_logs'] = logs_ascii[-1800:]
720-
return json.dumps(d_jobStatusSummary)
706+
# truncate logs, assuming worst case where every character needs to be escaped
707+
if len(logs) > 1800:
708+
d_jobStatusSummary['compute']['return']['job_logs'] = logs[-1800:]
709+
# PostgreSQL allows UTF-8, supports emojis, chinese, etc.
710+
return json.dumps(d_jobStatusSummary, ensure_ascii=False)

0 commit comments

Comments
 (0)