def host_dagit_ui( host, port, path_prefix, db_statement_timeout, port_lookup=True, read_only=False, suppress_warnings=False, **kwargs, ): if suppress_warnings: os.environ["PYTHONWARNINGS"] = "ignore" with get_instance_for_service("dagit") as instance: # Allow the instance components to change behavior in the context of a long running server process instance.optimize_for_dagit(db_statement_timeout) with get_workspace_process_context_from_kwargs( instance, version=__version__, read_only=read_only, kwargs=kwargs, ) as workspace_process_context: host_dagit_ui_with_workspace_process_context( workspace_process_context, host, port, path_prefix, port_lookup)
def test_execute_hammer_through_dagit(): with instance_for_test() as instance: with get_workspace_process_context_from_kwargs( instance, version="", read_only=False, kwargs={ "python_file": file_relative_path( __file__, "../../../dagster-test/dagster_test/toys/hammer.py" ), "attribute": "hammer_pipeline", }, ) as workspace_process_context: context = workspace_process_context.create_request_context() selector = infer_pipeline_selector(context, "hammer_pipeline") executor = SyncExecutor() variables = { "executionParams": { "runConfigData": { "execution": {"dask": {"config": {"cluster": {"local": {}}}}}, }, "selector": selector, "mode": "default", } } start_pipeline_result = graphql( request_string=LAUNCH_PIPELINE_EXECUTION_MUTATION, schema=create_schema(), context=context, variables=variables, executor=executor, ) if start_pipeline_result.errors: raise Exception("{}".format(start_pipeline_result.errors)) run_id = start_pipeline_result.data["launchPipelineExecution"]["run"]["runId"] context.instance.run_launcher.join(timeout=60) subscription = execute_dagster_graphql( context, SUBSCRIPTION_QUERY, variables={"runId": run_id} ) subscribe_results = [] subscription.subscribe(subscribe_results.append) messages = [ x["__typename"] for x in subscribe_results[0].data["pipelineRunLogs"]["messages"] ] assert "RunStartEvent" in messages assert "RunSuccessEvent" in messages
def test_smoke_app(gen_instance): with gen_instance() as instance: with get_workspace_process_context_from_kwargs( instance, version="", read_only=False, kwargs=dict(module_name="dagit_tests.toy.bar_repo", definition="bar"), ) as workspace_process_context: asgi_app = app.create_app_from_workspace_process_context( workspace_process_context) client = TestClient(asgi_app) result = client.post( "/graphql", json={"query": SMOKE_TEST_QUERY}, ) assert result.status_code == 200, result.content data = result.json() assert len(data["data"]["repositoriesOrError"]["nodes"]) == 1 assert len(data["data"]["repositoriesOrError"]["nodes"][0] ["pipelines"]) == 2 assert { node_data["name"] for node_data in data["data"]["repositoriesOrError"]["nodes"] [0]["pipelines"] } == set(["foo", "baz"]) result = client.get("/graphql") assert result.status_code == 400 assert result.content == b"No GraphQL query found in the request" result = client.get( "/dagit/notebook?path=foo.bar&repoLocName=foo_repo") assert result.status_code == 400 assert result.content.decode("utf-8") == "Invalid Path" result = client.post("/graphql", json={"query": "query { version { slkjd } }"}) data = result.json() assert "errors" in data assert len(data["errors"]) == 1 assert "must not have a sub selection" in data["errors"][0][ "message"] # Missing routes redirect to the index.html file of the Dagit react app, so the user # gets our UI when they navigate to "synthetic" react router URLs. result = client.get("foo/bar") assert result.status_code == 200, result.content result = client.get("pipelines/foo") assert result.status_code == 200, result.content
def load_dagit_for_workspace_cli_args(n_pipelines=1, **kwargs): instance = DagsterInstance.ephemeral() with get_workspace_process_context_from_kwargs( instance, version="", read_only=False, kwargs=kwargs ) as workspace_process_context: client = TestClient(create_app_from_workspace_process_context(workspace_process_context)) res = client.get( "/graphql?query={query_string}".format(query_string=PIPELINES_OR_ERROR_QUERY) ) json_res = res.json() assert "data" in json_res assert "repositoriesOrError" in json_res["data"] assert "nodes" in json_res["data"]["repositoriesOrError"] assert len(json_res["data"]["repositoriesOrError"]["nodes"][0]["pipelines"]) == n_pipelines return res