diff --git a/chris_backend/plugininstances/services/manager.py b/chris_backend/plugininstances/services/manager.py index 63716147..ab665ba8 100755 --- a/chris_backend/plugininstances/services/manager.py +++ b/chris_backend/plugininstances/services/manager.py @@ -70,8 +70,6 @@ class PluginInstanceManager(object): - __NONASCII = re.compile(r'[^\x00-\x7F]') - def __init__(self, plugin_instance): self.c_plugin_inst = plugin_instance @@ -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. """ @@ -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)