Example #1
0
def test_launch_run_with_unloadable_pipeline_grpc():
    with instance_for_test() as instance:
        with get_foo_pipeline_handle() as pipeline_handle:
            api_client = pipeline_handle.repository_handle.repository_location.client

            pipeline_run = instance.create_run(
                pipeline_name="foo",
                run_id=None,
                run_config={},
                mode="default",
                solids_to_execute=None,
                step_keys_to_execute=None,
                status=None,
                tags=None,
                root_run_id=None,
                parent_run_id=None,
                pipeline_snapshot=None,
                execution_plan_snapshot=None,
                parent_pipeline_snapshot=None,
            )
            run_id = pipeline_run.run_id

            original_origin = pipeline_handle.get_external_origin()

            # point the api to a pipeline that cannot be loaded
            res = deserialize_json_to_dagster_namedtuple(
                api_client.start_run(
                    ExecuteExternalPipelineArgs(
                        pipeline_origin=original_origin._replace(
                            pipeline_name="i_am_fake_pipeline"),
                        pipeline_run_id=run_id,
                        instance_ref=instance.get_ref(),
                    )))

            assert res.success
            finished_pipeline_run = poll_for_finished_run(instance, run_id)

            assert finished_pipeline_run
            assert finished_pipeline_run.run_id == run_id
            assert finished_pipeline_run.status == PipelineRunStatus.FAILURE

            poll_for_event(instance,
                           run_id,
                           event_type="ENGINE_EVENT",
                           message="Process for pipeline exited")
            event_records = instance.all_logs(run_id)
            _check_event_log_contains(
                event_records,
                [
                    ("ENGINE_EVENT", "Started process for pipeline"),
                    ("ENGINE_EVENT", "Could not load pipeline definition"),
                    (
                        "PIPELINE_FAILURE",
                        "This pipeline run has been marked as failed from outside the execution context",
                    ),
                    ("ENGINE_EVENT", "Process for pipeline exited"),
                ],
            )
Example #2
0
def test_launch_run_grpc():
    with instance_for_test() as instance:
        with get_bar_repo_repository_location(instance) as repository_location:
            pipeline_handle = PipelineHandle(
                "foo",
                repository_location.get_repository("bar_repo").handle)
            api_client = repository_location.client

            pipeline_run = instance.create_run(
                pipeline_name="foo",
                run_id=None,
                run_config={},
                mode="default",
                solids_to_execute=None,
                step_keys_to_execute=None,
                status=None,
                tags=None,
                root_run_id=None,
                parent_run_id=None,
                pipeline_snapshot=None,
                execution_plan_snapshot=None,
                parent_pipeline_snapshot=None,
            )
            run_id = pipeline_run.run_id

            res = deserialize_json_to_dagster_namedtuple(
                api_client.start_run(
                    ExecuteExternalPipelineArgs(
                        pipeline_origin=pipeline_handle.get_external_origin(),
                        pipeline_run_id=run_id,
                        instance_ref=instance.get_ref(),
                    )))

            assert res.success
            finished_pipeline_run = poll_for_finished_run(instance, run_id)

            assert finished_pipeline_run
            assert finished_pipeline_run.run_id == run_id
            assert finished_pipeline_run.status == PipelineRunStatus.SUCCESS

            poll_for_event(instance,
                           run_id,
                           event_type="ENGINE_EVENT",
                           message="Process for run exited")
            event_records = instance.all_logs(run_id)
            _check_event_log_contains(
                event_records,
                [("ENGINE_EVENT", msg) for msg in [
                    "Started process for run",
                    "Executing steps in process",
                    "Finished steps in process",
                    "Process for run exited",
                ]],
            )
Example #3
0
def test_launch_run_grpc():
    with instance_for_test() as instance:
        with get_foo_grpc_pipeline_handle() as pipeline_handle:
            api_client = pipeline_handle.repository_handle.repository_location_handle.client

            pipeline_run = instance.create_run(
                pipeline_name="foo",
                run_id=None,
                run_config={},
                mode="default",
                solids_to_execute=None,
                step_keys_to_execute=None,
                status=None,
                tags=None,
                root_run_id=None,
                parent_run_id=None,
                pipeline_snapshot=None,
                execution_plan_snapshot=None,
                parent_pipeline_snapshot=None,
            )
            run_id = pipeline_run.run_id

            res = api_client.start_run(
                ExecuteExternalPipelineArgs(
                    pipeline_origin=pipeline_handle.get_external_origin(),
                    pipeline_run_id=run_id,
                    instance_ref=instance.get_ref(),
                ))

            assert res.success
            finished_pipeline_run = poll_for_finished_run(instance, run_id)

            assert finished_pipeline_run
            assert finished_pipeline_run.run_id == run_id
            assert finished_pipeline_run.status == PipelineRunStatus.SUCCESS

            poll_for_event(instance,
                           run_id,
                           event_type="ENGINE_EVENT",
                           message="Process for pipeline exited")
            event_records = instance.all_logs(run_id)

            (started_process, executing_steps, finished_steps,
             process_exited) = tuple(_get_engine_events(event_records))

            assert "Started process for pipeline" in started_process.message
            assert "Executing steps in process" in executing_steps.message
            assert "Finished steps in process" in finished_steps.message
            assert "Process for pipeline exited" in process_exited.message
Example #4
0
def test_launch_unloadable_run_grpc():
    with instance_for_test() as instance:
        with get_bar_repo_repository_location(instance) as repository_location:
            pipeline_handle = PipelineHandle(
                "foo",
                repository_location.get_repository("bar_repo").handle)
            api_client = repository_location.client

            pipeline_run = instance.create_run(
                pipeline_name="foo",
                run_id=None,
                run_config={},
                mode="default",
                solids_to_execute=None,
                step_keys_to_execute=None,
                status=None,
                tags=None,
                root_run_id=None,
                parent_run_id=None,
                pipeline_snapshot=None,
                execution_plan_snapshot=None,
                parent_pipeline_snapshot=None,
            )
            run_id = pipeline_run.run_id

            with instance_for_test() as other_instance:
                res = deserialize_json_to_dagster_namedtuple(
                    api_client.start_run(
                        ExecuteExternalPipelineArgs(
                            pipeline_origin=pipeline_handle.
                            get_external_origin(),
                            pipeline_run_id=run_id,
                            instance_ref=other_instance.get_ref(),
                        )))

                assert not res.success
                assert (
                    "gRPC server could not load run {run_id} in order to execute it. "
                    "Make sure that the gRPC server has access to your run storage."
                    .format(run_id=run_id)
                    in res.serializable_error_info.message)
Example #5
0
def execute_run_grpc(api_client, instance_ref, pipeline_origin, pipeline_run):
    """Asynchronously execute a run over GRPC."""
    from dagster.grpc.client import DagsterGrpcClient

    check.inst_param(api_client, "api_client", DagsterGrpcClient)
    check.inst_param(instance_ref, "instance_ref", InstanceRef)
    check.inst_param(pipeline_origin, "pipeline_origin", ExternalPipelineOrigin)
    check.inst_param(pipeline_run, "pipeline_run", PipelineRun)

    with DagsterInstance.from_ref(instance_ref) as instance:
        yield instance.report_engine_event(
            'About to start process for pipeline "{pipeline_name}" (run_id: {run_id}).'.format(
                pipeline_name=pipeline_run.pipeline_name, run_id=pipeline_run.run_id
            ),
            pipeline_run,
            engine_event_data=EngineEventData(marker_start="cli_api_subprocess_init"),
        )

        run_did_fail = False

        execute_run_args = ExecuteExternalPipelineArgs(
            pipeline_origin=pipeline_origin,
            pipeline_run_id=pipeline_run.run_id,
            instance_ref=instance_ref,
        )
        for event in api_client.execute_run(execute_run_args=execute_run_args):
            if isinstance(event, IPCErrorMessage):
                yield instance.report_engine_event(
                    event.message,
                    pipeline_run=pipeline_run,
                    engine_event_data=EngineEventData(
                        marker_end="cli_api_subprocess_init", error=event.serializable_error_info
                    ),
                )
                if not run_did_fail:
                    run_did_fail = True
                    yield instance.report_run_failed(pipeline_run)
            else:
                yield event