Esempio n. 1
0
    def add_run(self, pipeline_run):
        check.inst_param(pipeline_run, "pipeline_run", PipelineRun)

        if pipeline_run.pipeline_snapshot_id and not self.has_pipeline_snapshot(
                pipeline_run.pipeline_snapshot_id):
            raise DagsterSnapshotDoesNotExist(
                "Snapshot {ss_id} does not exist in run storage".format(
                    ss_id=pipeline_run.pipeline_snapshot_id))

        with self.connect() as conn:
            try:
                runs_insert = RunsTable.insert().values(  # pylint: disable=no-value-for-parameter
                    run_id=pipeline_run.run_id,
                    pipeline_name=pipeline_run.pipeline_name,
                    status=pipeline_run.status.value,
                    run_body=serialize_dagster_namedtuple(pipeline_run),
                    snapshot_id=pipeline_run.pipeline_snapshot_id,
                )
                conn.execute(runs_insert)
            except db.exc.IntegrityError as exc:
                six.raise_from(DagsterRunAlreadyExists, exc)

            if pipeline_run.tags and len(pipeline_run.tags) > 0:
                conn.execute(
                    RunTagsTable.insert(),  # pylint: disable=no-value-for-parameter
                    [
                        dict(run_id=pipeline_run.run_id, key=k, value=v)
                        for k, v in pipeline_run.tags.items()
                    ],
                )

        return pipeline_run
Esempio n. 2
0
    def add_run(self, pipeline_run: PipelineRun) -> PipelineRun:
        check.inst_param(pipeline_run, "pipeline_run", PipelineRun)

        if pipeline_run.pipeline_snapshot_id and not self.has_pipeline_snapshot(
                pipeline_run.pipeline_snapshot_id):
            raise DagsterSnapshotDoesNotExist(
                "Snapshot {ss_id} does not exist in run storage".format(
                    ss_id=pipeline_run.pipeline_snapshot_id))

        has_tags = pipeline_run.tags and len(pipeline_run.tags) > 0
        partition = pipeline_run.tags.get(
            PARTITION_NAME_TAG) if has_tags else None
        partition_set = pipeline_run.tags.get(
            PARTITION_SET_TAG) if has_tags else None
        if self.has_built_index(MODE_MIGRATION):
            runs_insert = RunsTable.insert().values(  # pylint: disable=no-value-for-parameter
                run_id=pipeline_run.run_id,
                pipeline_name=pipeline_run.pipeline_name,
                mode=pipeline_run.mode,
                status=pipeline_run.status.value,
                run_body=serialize_dagster_namedtuple(pipeline_run),
                snapshot_id=pipeline_run.pipeline_snapshot_id,
                partition=partition,
                partition_set=partition_set,
            )
        else:
            runs_insert = RunsTable.insert().values(  # pylint: disable=no-value-for-parameter
                run_id=pipeline_run.run_id,
                pipeline_name=pipeline_run.pipeline_name,
                status=pipeline_run.status.value,
                run_body=serialize_dagster_namedtuple(pipeline_run),
                snapshot_id=pipeline_run.pipeline_snapshot_id,
                partition=partition,
                partition_set=partition_set,
            )
        with self.connect() as conn:
            try:
                conn.execute(runs_insert)
            except db.exc.IntegrityError as exc:
                raise DagsterRunAlreadyExists from exc

            if pipeline_run.tags and len(pipeline_run.tags) > 0:
                conn.execute(
                    RunTagsTable.insert(),  # pylint: disable=no-value-for-parameter
                    [
                        dict(run_id=pipeline_run.run_id, key=k, value=v)
                        for k, v in pipeline_run.tags.items()
                    ],
                )

        return pipeline_run
Esempio n. 3
0
    def add_run(self, pipeline_run):
        check.inst_param(pipeline_run, "pipeline_run", PipelineRun)
        if self._runs.get(pipeline_run.run_id):
            raise DagsterRunAlreadyExists(
                "Can not add same run twice for run_id {run_id}".format(
                    run_id=pipeline_run.run_id), )
        if pipeline_run.pipeline_snapshot_id:
            if not self.has_pipeline_snapshot(
                    pipeline_run.pipeline_snapshot_id):
                raise DagsterSnapshotDoesNotExist(
                    "pipeline_snapshot_id {ss_id} does not exist in run storage."
                    .format(ss_id=pipeline_run.pipeline_snapshot_id))

        self._runs[pipeline_run.run_id] = pipeline_run
        if pipeline_run.tags and len(pipeline_run.tags) > 0:
            self._run_tags[pipeline_run.run_id] = frozendict(pipeline_run.tags)

        return pipeline_run