def playbook_on_task_start(self, name, is_conditional): self.task_uuid = uuid.uuid1().hex create_time = datetime.datetime.now() create_time = create_time.strftime('%Y-%m-%dT%H:%M:%SZ%z') for tag in self.tag_hosts: Service.add_log(global_id=self.global_id, source=self.source, task_uuid=self.task_uuid, task_status="", create_time=create_time, end_time="", data="", host=tag)
def add_log(self, task_status, detail): begin_time = time.strftime(self.TIME_FORMAT, time.localtime()) for i in range(1, self.max_try + 1): try: Service.add_log(global_id=self.global_id, source=self.source, task_uuid=self.uid, task_status=task_status, create_time=begin_time, end_time="", data=detail, host=self.host, task_id=self.task_id) return except Exception as err: Logger.error('Add log err for %d times: {}'.format(str(err)) % i) raise AnsibleError("Add log DB error retry for %d times" % self.max_try)