Truncate job args/kwargs to a reasonable length (#1277)

* Truncate job args/kwargs to a reasonable length

* fix
main
JhonnyBn 5 years ago committed by GitHub
parent 29222ea12f
commit 6eec0065df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,6 +39,11 @@ JobStatus = enum(
UNEVALUATED = object() UNEVALUATED = object()
def truncate_long_string(data, maxlen=75):
""" Truncates strings longer than maxlen
"""
return (data[:maxlen] + '...') if len(data) > maxlen else data
def cancel_job(job_id, connection=None): def cancel_job(job_id, connection=None):
"""Cancels the job with the given job ID, preventing execution. Discards """Cancels the job with the given job ID, preventing execution. Discards
any job info (i.e. it can't be requeued later). any job info (i.e. it can't be requeued later).
@ -672,9 +677,9 @@ class Job(object):
if self.func_name is None: if self.func_name is None:
return None return None
arg_list = [as_text(repr(arg)) for arg in self.args] arg_list = [as_text(truncate_long_string(repr(arg))) for arg in self.args]
kwargs = ['{0}={1}'.format(k, as_text(repr(v))) for k, v in self.kwargs.items()] kwargs = ['{0}={1}'.format(k, as_text(truncate_long_string(repr(v)))) for k, v in self.kwargs.items()]
# Sort here because python 3.3 & 3.4 makes different call_string # Sort here because python 3.3 & 3.4 makes different call_string
arg_list += sorted(kwargs) arg_list += sorted(kwargs)
args = ', '.join(arg_list) args = ', '.join(arg_list)

Loading…
Cancel
Save