def subtask_create(self, task_uuid, title, description=None, context=None): subtask = models.Subtask(task_uuid=task_uuid) subtask.update({ "title": title, "description": description or "", "context": context or {}, }) subtask.save() return subtask
def task_result_create(self, task_uuid, key, data): raw_data = data.get("raw", []) iter_count = len(raw_data) failed_iter_count = 0 max_duration = 0 min_duration = 0 success = True for d in raw_data: if d.get("error"): failed_iter_count += 1 duration = d.get("duration", 0) if duration > max_duration: max_duration = duration if min_duration and min_duration > duration: min_duration = duration sla = data.get("sla", []) # TODO(ikhudoshyn): if no SLA was specified and there are # failed iterations is it success? # NOTE(ikhudoshyn): we call it 'pass_sla' # for the sake of consistency with other models # so if no SLAs were specified, then we assume pass_sla == True success = all([s.get("success") for s in sla]) now = timeutils.utcnow() delta = dt.timedelta(seconds=data.get("full_duration", 0)) start = now - delta subtask = models.Subtask() subtask.update({"task_uuid": task_uuid}) subtask.save() workload = models.Workload() workload.update({ "task_uuid": task_uuid, "subtask_uuid": subtask.uuid, "name": key["name"], "position": key["pos"], "runner": key["kw"]["runner"], "runner_type": key["kw"]["runner"]["type"], "context": key["kw"].get("context", {}), "hooks": data.get("hooks", []), "sla": key["kw"].get("sla", {}), "args": key["kw"].get("args", {}), "sla_results": {"sla": sla}, "context_execution": {}, "load_duration": data.get("load_duration", 0), "full_duration": data.get("full_duration", 0), "min_duration": min_duration, "max_duration": max_duration, "total_iteration_count": iter_count, "failed_iteration_count": failed_iter_count, # TODO(ikhudoshyn) "start_time": start, "statistics": {}, "pass_sla": success }) workload.save() workload_data = models.WorkloadData() workload_data.update({ "task_uuid": task_uuid, "workload_uuid": workload.uuid, "chunk_order": 0, "iteration_count": iter_count, "failed_iteration_count": failed_iter_count, "chunk_data": {"raw": raw_data}, # TODO(ikhudoshyn) "chunk_size": 0, "compressed_chunk_size": 0, "started_at": start, "finished_at": now }) # TODO(ikhudoshyn): create workload and workload data in # one transaction workload_data.save() # TODO(ikhudoshyn): if pass_sla is False, # then update task's and subtask's pass_sla # TODO(ikhudoshyn): update task.task_duration # and subtask.duration return self._make_old_task_result(workload, workload_data)