Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init_record(msg):
"""Initialize a TaskRecord based on a request."""
header = msg['header']
return {
'msg_id' : header['msg_id'],
'header' : header,
'content': msg['content'],
'metadata': msg['metadata'],
'buffers': msg['buffers'],
'submitted': util.ensure_timezone(header['date']),
'client_uuid' : None,
'engine_uuid' : None,
'started': None,
'completed': None,
'resubmitted': None,
'received': None,
'result_header' : None,
'result_metadata': None,
'result_content' : None,
'result_buffers' : None,
'queue' : None,
'execute_input' : None,
'execute_result': None,
'error': None,
'stdout': '',
'stderr': '',
outstanding = self.queues[eid]
for msg_id in outstanding:
self.pending.remove(msg_id)
self.all_completed.add(msg_id)
try:
raise error.EngineError("Engine %r died while running task %r" % (eid, msg_id))
except:
content = error.wrap_exception()
# build a fake header:
header = {}
header['engine'] = uuid
header['date'] = util.utcnow()
rec = dict(result_content=content, result_header=header, result_buffers=[])
rec['completed'] = util.ensure_timezone(header['date'])
rec['engine_uuid'] = uuid
try:
self.db.update_record(msg_id, rec)
except Exception:
self.log.error("DB Error handling stranded msg %r", msg_id, exc_info=True)
def _add_tz(obj):
if isinstance(obj, datetime):
obj = ensure_timezone(obj)
return obj
def _convert_timestamp(s):
"""Adapt text timestamp to datetime"""
return ensure_timezone(dateutil_parse(s))