def create(call: APICall, fields: dict): identity = call.identity now = datetime.utcnow() return Task( id=create_id(), user=identity.user, company=identity.company, created=now, last_update=now, **fields, )
def clone_task( cls, company_id, user_id, task_id, name: Optional[str] = None, comment: Optional[str] = None, parent: Optional[str] = None, project: Optional[str] = None, tags: Optional[Sequence[str]] = None, system_tags: Optional[Sequence[str]] = None, execution_overrides: Optional[dict] = None, ) -> Task: task = cls.get_by_id(company_id=company_id, task_id=task_id) execution_dict = task.execution.to_proper_dict() if task.execution else {} if execution_overrides: parameters = execution_overrides.get("parameters") if parameters is not None: execution_overrides["parameters"] = { ParameterKeyEscaper.escape(k): v for k, v in parameters.items() } execution_dict = deep_merge(execution_dict, execution_overrides) artifacts = execution_dict.get("artifacts") if artifacts: execution_dict["artifacts"] = [ a for a in artifacts if a.get("mode") != ArtifactModes.output ] now = datetime.utcnow() with translate_errors_context(): new_task = Task( id=create_id(), user=user_id, company=company_id, created=now, last_update=now, name=name or task.name, comment=comment or task.comment, parent=parent or task.parent, project=project or task.project, tags=tags or task.tags, system_tags=system_tags or [], type=task.type, script=task.script, output=Output(destination=task.output.destination) if task.output else None, execution=execution_dict, ) cls.validate(new_task) new_task.save() return new_task
def clone_task( cls, company_id, user_id, task_id, name: Optional[str] = None, comment: Optional[str] = None, parent: Optional[str] = None, project: Optional[str] = None, tags: Optional[Sequence[str]] = None, system_tags: Optional[Sequence[str]] = None, hyperparams: Optional[dict] = None, configuration: Optional[dict] = None, execution_overrides: Optional[dict] = None, validate_references: bool = False, ) -> Task: task = cls.get_by_id(company_id=company_id, task_id=task_id, allow_public=True) execution_dict = task.execution.to_proper_dict() if task.execution else {} execution_model_overriden = False params_dict = { field: value for field, value in ( ("hyperparams", hyperparams), ("configuration", configuration), ) if value is not None } if execution_overrides: params_dict["execution"] = {} for legacy_param in ("parameters", "configuration"): legacy_value = execution_overrides.pop(legacy_param, None) if legacy_value is not None: params_dict["execution"] = legacy_value execution_dict = deep_merge(execution_dict, execution_overrides) execution_model_overriden = execution_overrides.get("model") is not None params_prepare_for_save(params_dict, previous_task=task) artifacts = execution_dict.get("artifacts") if artifacts: execution_dict["artifacts"] = [ a for a in artifacts if a.get("mode") != ArtifactModes.output ] now = datetime.utcnow() with translate_errors_context(): new_task = Task( id=create_id(), user=user_id, company=company_id, created=now, last_update=now, name=name or task.name, comment=comment or task.comment, parent=parent or task.parent, project=project or task.project, tags=tags or task.tags, system_tags=system_tags or [], type=task.type, script=task.script, output=Output(destination=task.output.destination) if task.output else None, execution=execution_dict, configuration=params_dict.get("configuration") or task.configuration, hyperparams=params_dict.get("hyperparams") or task.hyperparams, ) cls.validate( new_task, validate_model=validate_references or execution_model_overriden, validate_parent=validate_references or parent, validate_project=validate_references or project, ) new_task.save() if task.project == new_task.project: updated_tags = tags updated_system_tags = system_tags else: updated_tags = new_task.tags updated_system_tags = new_task.system_tags org_bll.update_tags( company_id, Tags.Task, project=new_task.project, tags=updated_tags, system_tags=updated_system_tags, ) return new_task