def format_task_error(headline, task, command, formatted_exception=None): """ Format a message body for an error email related to a luigi.task.Task :param headline: Summary line for the message :param task: `luigi.task.Task` instance where this error occurred :param formatted_exception: optional string showing traceback :return: message body """ if formatted_exception: formatted_exception = wrap_traceback(formatted_exception) else: formatted_exception = "" if email().format == 'html': msg_template = textwrap.dedent(''' <html> <body> <h2>{headline}</h2> <table style="border-top: 1px solid black; border-bottom: 1px solid black"> <thead> <tr><th>name</th><td>{name}</td></tr> </thead> <tbody> {param_rows} </tbody> </table> </pre> <h2>Command line</h2> <pre> {command} </pre> <h2>Traceback</h2> {traceback} </body> </html> ''') str_params = task.to_str_params() params = '\n'.join('<tr><th>{}</th><td>{}</td></tr>'.format(*items) for items in str_params.items()) body = msg_template.format(headline=headline, name=task.task_family, param_rows=params, command=command, traceback=formatted_exception) else: msg_template = textwrap.dedent('''\ {headline} Name: {name} Parameters: {params} Command line: {command} {traceback} ''') str_params = task.to_str_params() max_width = max([0] + [len(x) for x in str_params.keys()]) params = '\n'.join(' {:{width}}: {}'.format(*items, width=max_width) for items in str_params.items()) body = msg_template.format(headline=headline, name=task.task_family, params=params, command=command, traceback=formatted_exception) return body
def format_task_error(headline, task, formatted_exception=None): """ Format a message body for an error email related to a luigi.task.Task :param headline: Summary line for the message :param task: `luigi.task.Task` instance where this error occurred :param formatted_exception: optional string showing traceback :return: message body """ typ = email_type() if formatted_exception: formatted_exception = wrap_traceback(formatted_exception) else: formatted_exception = "" if typ == 'html': msg_template = textwrap.dedent(''' <html> <body> <h2>{headline}</h2> <table style="border-top: 1px solid black; border-bottom: 1px solid black"> <thead> <tr><th>name</th><td>{name}</td></tr> </thead> <tbody> {param_rows} </tbody> </table> </pre> <h2>Traceback</h2> {traceback} </body> </html> ''') str_params = task.to_str_params() params = '\n'.join('<tr><th>{}</th><td>{}</td></tr>'.format(*items) for items in str_params.items()) body = msg_template.format(headline=headline, name=task.task_family, param_rows=params, traceback=formatted_exception) else: msg_template = textwrap.dedent('''\ {headline} Name: {name} Parameters: {params} {traceback} ''') str_params = task.to_str_params() max_width = max([0] + [len(x) for x in str_params.keys()]) params = '\n'.join(' {:{width}}: {}'.format(*items, width=max_width) for items in str_params.items()) body = msg_template.format(headline=headline, name=task.task_family, params=params, traceback=formatted_exception) return body
def get_hash(task): hashables = {'cls': task.__class__.__name__, **task.to_str_params()} hash_str = json.dumps(hashables, separators=(',', ':'), sort_keys=True) task_hash = hashlib.md5(hash_str.encode('utf-8')).hexdigest() return task_hash