コード例 #1
0
    def compile_and_execute(self, manifest, ctx):
        result = None
        self.adapter.acquire_connection(self.node.get('name'))
        with collect_timing_info('compile') as timing_info:
            # if we fail here, we still have a compiled node to return
            # this has the benefit of showing a build path for the errant
            # model
            ctx.node = self.compile(manifest)
        ctx.timing.append(timing_info)

        # for ephemeral nodes, we only want to compile, not run
        if not ctx.node.is_ephemeral_model:
            with collect_timing_info('execute') as timing_info:
                result = self.run(ctx.node, manifest)
                ctx.node = result.node

            ctx.timing.append(timing_info)

        return result
コード例 #2
0
    def safe_run(self, manifest):
        catchable_errors = (CompilationException, RuntimeException)

        # result = self.DefaultResult(self.node)
        started = time.time()
        timing = []
        error = None
        node = self.node
        result = None

        try:
            with collect_timing_info('compile') as timing_info:
                # if we fail here, we still have a compiled node to return
                # this has the benefit of showing a build path for the errant
                # model
                node = self.compile(manifest)

            timing.append(timing_info)

            # for ephemeral nodes, we only want to compile, not run
            if not node.is_ephemeral_model:
                with collect_timing_info('execute') as timing_info:
                    result = self.run(node, manifest)
                    node = result.node

                timing.append(timing_info)

            # result.extend(item.serialize() for item in timing)

        except catchable_errors as e:
            if e.node is None:
                e.node = node

            error = dbt.compat.to_string(e)

        except InternalException as e:
            build_path = self.node.build_path
            prefix = 'Internal error executing {}'.format(build_path)

            error = "{prefix}\n{error}\n\n{note}".format(
                         prefix=dbt.ui.printer.red(prefix),
                         error=str(e).strip(),
                         note=INTERNAL_ERROR_STRING)
            logger.debug(error)
            error = dbt.compat.to_string(e)

        except Exception as e:
            node_description = self.node.get('build_path')
            if node_description is None:
                node_description = self.node.unique_id
            prefix = "Unhandled error while executing {description}".format(
                        description=node_description)

            error = "{prefix}\n{error}".format(
                         prefix=dbt.ui.printer.red(prefix),
                         error=str(e).strip())

            logger.error(error)
            logger.debug('', exc_info=True)
            error = dbt.compat.to_string(e)

        finally:
            exc_str = self._safe_release_connection()

            # if releasing failed and the result doesn't have an error yet, set
            # an error
            if exc_str is not None and result.error is None:
                error = exc_str

        if error is not None:
            # we could include compile time for runtime errors here
            result = self.error_result(node, error, started, [])
        elif result is not None:
            result = self.from_run_result(result, started, timing)
        else:
            result = self.ephemeral_result(node, started, timing)
        return result
コード例 #3
0
    def safe_run(self, manifest):
        catchable_errors = (CompilationException, RuntimeException)

        # result = self.DefaultResult(self.node)
        started = time.time()
        timing = []
        error = None
        node = self.node
        result = None

        try:
            with collect_timing_info('compile') as timing_info:
                # if we fail here, we still have a compiled node to return
                # this has the benefit of showing a build path for the errant
                # model
                node = self.compile(manifest)

            timing.append(timing_info)

            # for ephemeral nodes, we only want to compile, not run
            if not node.is_ephemeral_model:
                with collect_timing_info('execute') as timing_info:
                    result = self.run(node, manifest)
                    node = result.node

                timing.append(timing_info)

            # result.extend(item.serialize() for item in timing)

        except catchable_errors as e:
            if e.node is None:
                e.node = node

            error = dbt.compat.to_string(e)

        except InternalException as e:
            build_path = self.node.build_path
            prefix = 'Internal error executing {}'.format(build_path)

            error = "{prefix}\n{error}\n\n{note}".format(
                prefix=dbt.ui.printer.red(prefix),
                error=str(e).strip(),
                note=INTERNAL_ERROR_STRING)
            logger.debug(error)
            error = dbt.compat.to_string(e)

        except Exception as e:
            node_description = self.node.get('build_path')
            if node_description is None:
                node_description = self.node.unique_id
            prefix = "Unhandled error while executing {description}".format(
                description=node_description)

            error = "{prefix}\n{error}".format(
                prefix=dbt.ui.printer.red(prefix), error=str(e).strip())

            logger.error(error)
            logger.debug('', exc_info=True)
            error = dbt.compat.to_string(e)

        finally:
            exc_str = self._safe_release_connection()

            # if releasing failed and the result doesn't have an error yet, set
            # an error
            if exc_str is not None and result.error is None:
                error = exc_str

        if error is not None:
            # we could include compile time for runtime errors here
            result = self.error_result(node, error, started, [])
        elif result is not None:
            result = self.from_run_result(result, started, timing)
        else:
            result = self.ephemeral_result(node, started, timing)
        return result