def save_task_result(self, idents, msg):
client_id = idents[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>msg = self.session.unserialize(msg)<EOL><DEDENT>except Exception:<EOL><INDENT>self.log.error("<STR_LIT>",<EOL>client_id, msg, exc_info=True)<EOL>return<EOL><DEDENT>parent = msg['<STR_LIT>']<EOL>if not parent:<EOL><INDENT>self.log.warn("<STR_LIT>", msg)<EOL>return<EOL><DEDENT>msg_id = parent['<STR_LIT>']<EOL>if msg_id in self.unassigned:<EOL><INDENT>self.unassigned.remove(msg_id)<EOL><DEDENT>header = msg['<STR_LIT>']<EOL>engine_uuid = header.get('<STR_LIT>', u'<STR_LIT>')<EOL>eid = self.by_ident.get(cast_bytes(engine_uuid), None)<EOL>status = header.get('<STR_LIT:status>', None)<EOL>if msg_id in self.pending:<EOL><INDENT>self.log.info("<STR_LIT>", msg_id, eid)<EOL>self.pending.remove(msg_id)<EOL>self.all_completed.add(msg_id)<EOL>if eid is not None:<EOL><INDENT>if status != '<STR_LIT>':<EOL><INDENT>self.completed[eid].append(msg_id)<EOL><DEDENT>if msg_id in self.tasks[eid]:<EOL><INDENT>self.tasks[eid].remove(msg_id)<EOL><DEDENT><DEDENT>completed = header['<STR_LIT:date>']<EOL>started = header.get('<STR_LIT>', None)<EOL>result = {<EOL>'<STR_LIT>' : header,<EOL>'<STR_LIT>': msg['<STR_LIT:content>'],<EOL>'<STR_LIT>' : started,<EOL>'<STR_LIT>' : completed,<EOL>'<STR_LIT>' : datetime.now(),<EOL>'<STR_LIT>': engine_uuid,<EOL>}<EOL>result['<STR_LIT>'] = msg['<STR_LIT>']<EOL>try:<EOL><INDENT>self.db.update_record(msg_id, result)<EOL><DEDENT>except Exception:<EOL><INDENT>self.log.error("<STR_LIT>", msg_id, exc_info=True)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.log.debug("<STR_LIT>", msg_id)<EOL><DEDENT>
save the result of a completed task.