コード例 #1
0
ファイル: db.py プロジェクト: yaronha/mlrun
    def store_function(
        self, session, function, name, project="", tag="", versioned=False
    ):
        project = project or config.default_project
        self._create_project_if_not_exists(session, project)
        tag = tag or get_in(function, "metadata.tag") or "latest"
        hash_key = fill_function_hash(function, tag)

        # clear tag from object in case another function will "take" that tag
        update_in(function, "metadata.tag", "")

        # versioned means whether we want to version this function object so that it will queryable by its hash key
        # to enable that we set the uid to the hash key so it will have a unique record (Unique constraint of function
        # is the set (project, name, uid))
        # when it's not enabled it means we want to have one unique function object for the set (project, name, tag)
        # that will be reused on every store function (cause we don't want to version each version e.g. create a new
        # record) so we set the uid to be unversioned-{tag}
        if versioned:
            uid = hash_key
        else:
            uid = f'unversioned-{tag}'

        updated = datetime.now(timezone.utc)
        update_in(function, "metadata.updated", updated)
        fn = self._get_function(session, name, project, uid)
        if not fn:
            fn = Function(name=name, project=project, uid=uid,)
        fn.updated = updated
        labels = get_in(function, "metadata.labels", {})
        update_labels(fn, labels)
        fn.struct = function
        self._upsert(session, fn)
        self.tag_objects_v2(session, [fn], project, tag)
        return hash_key
コード例 #2
0
ファイル: db.py プロジェクト: zhuohuwu0603/mlrun
 def store_artifact(self,
                    session,
                    key,
                    artifact,
                    uid,
                    iter=None,
                    tag="",
                    project=""):
     project = project or config.default_project
     self._create_project_if_not_exists(session, project)
     artifact = artifact.copy()
     updated = artifact.get("updated")
     if not updated:
         updated = artifact["updated"] = datetime.now(timezone.utc)
     if iter:
         key = "{}-{}".format(iter, key)
     art = self._get_artifact(session, uid, project, key)
     labels = artifact.get("labels", {})
     if not art:
         art = Artifact(key=key, uid=uid, updated=updated, project=project)
     update_labels(art, labels)
     art.struct = artifact
     self._upsert(session, art)
     if tag:
         self.tag_objects(session, [art], project, tag)
コード例 #3
0
ファイル: db.py プロジェクト: yaronha/mlrun
 def store_run(self, session, struct, uid, project="", iter=0):
     project = project or config.default_project
     self._create_project_if_not_exists(session, project)
     run = self._get_run(session, uid, project, iter)
     if not run:
         run = Run(
             uid=uid,
             project=project,
             iteration=iter,
             state=run_state(struct),
             start_time=run_start_time(struct) or datetime.now(),
         )
     labels = run_labels(struct)
     update_labels(run, labels)
     run.struct = struct
     self._upsert(session, run, ignore=True)